当前位置: 首页 > 知识库问答 >
问题:

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

穆建华
2023-03-14
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)

我在这里的编码

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个答案

公孙宇
2023-03-14

假设您使用Eclipse并将项目配置为Dynamic Web Project-->选择配置构建路径-->现在单击add jars按钮-->并选择Gson JAR-->单击OK

重新发布项目并重新启动服务器。

否则,将jar添加到war中的WEB-INF\lib目录

 类似资料: