Tomcat7 HTTP Status 500 - Servlet execution threw an exception

Pandiyan Muthu picture Pandiyan Muthu · Nov 30, 2012 · Viewed 26.8k times · Source
type Exception report

message Servlet execution threw an exception

description The server encountered an internal error that prevented it from fulfilling this request.

exception 

javax.servlet.ServletException: Servlet execution threw an exception


root cause 

java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
    java.lang.ClassLoader.defineClass1(Native Method)
    java.lang.ClassLoader.defineClassCond(Unknown Source)
    java.lang.ClassLoader.defineClass(Unknown Source)
    java.security.SecureClassLoader.defineClass(Unknown Source)
    org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2904)
    org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1173)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1681)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    Hello.doGet(Hello.java:42)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)


root cause 

java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeException
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    java.lang.ClassLoader.defineClass1(Native Method)
    java.lang.ClassLoader.defineClassCond(Unknown Source)
    java.lang.ClassLoader.defineClass(Unknown Source)
    java.security.SecureClassLoader.defineClass(Unknown Source)
    org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2904)
    org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1173)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1681)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    Hello.doGet(Hello.java:42)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.33 logs.

and My Coding Here

import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import java.io.*;

import java.sql.*;

import net.sf.json.JSONArray;

import net.sf.json.JSONObject;
/**
 * Servlet implementation class Getting_data
 */

public class Hello extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public Hello() {

    }
        public void doGet(HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException
        {

            res.setContentType("text/html");
        PrintWriter pw = res.getWriter();
        Connection con;
        Statement stmt;
        ResultSet rs = null;
        try{
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        con = DriverManager.getConnection("jdbc:odbc:Emp_info");
        stmt = con.createStatement();
        String query = "select * from Emp_table";// where employee_name='"+emp_name+"' or department='"+emp_dept+"' or email='"+email+"' order by employee_name";
        System.out.println("query " + query);
        rs = stmt.executeQuery(query);
        pw.println("Id"+"Name"+"Address"+"<br>");
       JSONArray arrayObj=new JSONArray();
        JSONArray arrayObj1=new JSONArray();
        JSONObject responseData = new JSONObject();
        while(rs.next())
        {
        //pw.println(rs.getString(1) + " " + rs.getString(2) + "<br>");
        String name = rs.getString(1);
        String name1 = rs.getString(2);
        arrayObj.add(new String(name));
        arrayObj1.add(new String(name1));
        }
        responseData.put("rows", arrayObj);
        responseData.put("data", arrayObj);
        pw.print(responseData);
        }


        catch (Exception e){
        pw.println(e);
        }
        }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

}

Answer

Sudhakar picture Sudhakar · Feb 10, 2013

Assuming your using Eclipse and the project configured as Dynamic Web Project Right click on your project --> choose configure build path --> now click on add jars button --> and select the Gson jar --> clickOK.

Republish the project and restart the server.

Else add the jar to WEB-INF\lib directoryinside the war

Or directly into the Deployed location in the tomcat , but in the same directory as mentioned