页面加载时Tomcat错误500

时间:2014-08-22 07:28:16

标签: servlets tomcat7

我在Tomcat上收到以下错误。 代码如下:

消息Servlet执行引发异常

说明服务器遇到内部错误,导致无法完成此请求。

例外

javax.servlet.ServletException: Servlet execution threw an exception
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpher
    DBChart.doGet(DBChart.java:68)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

java.lang.ClassNotFoundException: net.sf.ezmorph.Morpher
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
    DBChart.doGet(DBChart.java:68)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

以下是我的Java文件

//imported all the required packages here   
class DBChart extends HttpServlet
{

    Connection c = null;
    Statement st = null;
    ResultSet rs = null;
    String query = null;
    JSONObject obj = null;
    JSONObject resobj = null;
    PreparedStatement pst = null;
    DatabaseMetaData dbmd = null;
    String dbURL = "jdbc:sqlserver://localhost:1433; databaseName = EMPLOYEE";
    String user = "username";
    String password = "mypassword";

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        try
        {
            List<JSONObject> Details = new LinkedList<JSONObject>();
            PrintWriter out = response.getWriter();
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            c = DriverManager.getConnection(dbURL, user, password);
            query = " select DeptName, NumberOfEmployess from Departments";
            pst = c.prepareStatement(query);
            rs = pst.executeQuery();
            while (rs.next())
            {
                String dept = rs.getString(1);
                int empnumber = rs.getInt(2);
                obj = new JSONObject();
                obj.put("DepartmentName", dept);
                obj.put("EmployeesinNumbers", empnumber);
                Details.add(obj);
            }
            resobj.put("RelativeDetails", Details);
            out.write(resobj.toString());

        }
        catch (Exception e)
        {
            System.out.println("Exception " + e);
        }
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        doGet(request, response);
    }
}

我确保在XMl文件中提到了正确的名称并使用了以下网址:

http://localhost:8080/DBCHART/db 

1 个答案:

答案 0 :(得分:0)

你的班级需要公开:

  

public class DBChart扩展了HttpServlet