Java 如何修复“HTTP 状态 500- Servlet 异常引发异常”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21346489/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 08:10:39  来源:igfitidea点击:

how to fix "HTTP Status 500- Servlet exception threw an exception"

javahibernatetomcatservlets

提问by mellodi

i got this erore and i don't know what's wrong i just want to check the username & password and then enter a page that shows it login or not

我得到了这个错误,我不知道出了什么问题,我只想检查用户名和密码,然后输入一个显示它是否登录的页面

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);
}

}

}

and this is the error

这是错误

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 help , i really can't understand what's wrong

请帮忙,我真的不明白出了什么问题

采纳答案by MorbidDesign

You need to put hibernate3.jar in classpath, specifically in the WEB-INF/libof your deployed application.

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

In Eclipse IDE, you can do this right-clicking on your project -> Properties -> Deployment Assembly.

在 Eclipse IDE 中,您可以右键单击您的项目 -> 属性 -> 部署程序集。

Click Add... button, select Java Build Path Entries and click Next. Then select the desired jars to be exported to WEB-INF/liband click Finish. Automatically, the source jars will be deployed in the correct path.

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

I hope this helps. It did for me.

我希望这有帮助。它对我有用。

回答by Aditya

remove the jar files and add them again in WEB-INF/lib

删除 jar 文件并在 WEB-INF/lib 中再次添加它们