Tomcat7 HTTP状态500 - Servlet执行引发异常

时间:2012-11-30 04:35:53

标签: servlets tomcat7 blackberry-jde

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)

注意Apache Tomcat / 7.0.33日志中提供了根本原因的完整堆栈跟踪。

和我的编码在这里

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
    }

}

1 个答案:

答案 0 :(得分:2)

假设您使用Eclipse并将项目配置为动态Web项目右键单击您的项目 - &gt;选择configure build path - &gt;现在click on add jars button - &gt;和select the Gson jar - &gt;点击OK

Republish项目和restart服务器。

否则将战争加入战争中的WEB-INF\lib directory

或直接进入tomcat中的Deployed位置,但与提及的目录相同