如何修复“HTTP Status 500- Servlet异常抛出异常”

时间:2014-01-25 04:09:33

标签: java hibernate tomcat servlets

我得到了这个错误,我不知道什么是错的 我只是想查看用户名和&密码,然后输入显示登录名称的页面

package cse;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.Date;
import java.util.Random;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@SuppressWarnings("serial")
@WebServlet(urlPatterns = {"/LogIn"})
public class LogIn extends HttpServlet {

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) 
    throws IOException {
    String username = request.getParameter("username");
    String password = request.getParameter("password");

    User signedInUser = User.login(username, password);

    if(!signedInUser.equals(null)){
         HttpSession s = request.getSession();
         s.setAttribute("signedInKey", (new Date()).getTime() + (new         Random()).nextInt(999999999));
         request.setAttribute("user", signedInUser);
         String url = "http://localhost:8080/java_project/test.jsp";
         response.sendRedirect(url);
    }

    String url = "http://localhost:8080/java_project/notLogIn.jsp";
    response.sendRedirect(url);
}

}

这是错误

HTTP Status 500 - Servlet execution threw an exception

   --------------------------------------------------------------------------------

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/hibernate/Session
ir.ac.shirazu.cse.LogIn.doPost(LogIn.java:25)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)


 root cause 

 java.lang.ClassNotFoundException: org.hibernate.Session
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
ir.ac.shirazu.cse.LogIn.doPost(LogIn.java:25)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
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.40 logs.


    --------------------------------------------------------------------------------

    Apache Tomcat/7.0.40

PLZ帮助,我真的无法理解什么是错的

2 个答案:

答案 0 :(得分:1)

您需要将hibernate3.jar放在类路径中,特别是在已部署应用程序的WEB-INF/lib中。

在Eclipse IDE中,您可以右键单击项目 - >属性 - >部署大会。

单击Add ...按钮,选择Java Build Path Entries并单击Next。然后选择要导出到WEB-INF/lib的所需jar并单击Finish。源代码将自动部署在正确的路径中。

我希望这会有所帮助。它确实适合我。

答案 1 :(得分:1)

删除jar文件并在WEB-INF / lib

中再次添加它们