gpt4 book ai didi

java - 如何修复 "HTTP Status 500- Servlet exception threw an exception"

转载 作者:行者123 更新时间:2023-11-29 00:01:06 26 4
gpt4 key购买 nike

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

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

求助,我真的不明白哪里出了问题

最佳答案

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

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

单击“添加...”按钮,选择“Java 构建路径条目”并单击“下一步”。然后选择要导出到 WEB-INF/lib 的所需 jar,然后单击“完成”。源 jar 将自动部署在正确的路径中。

希望对您有所帮助。它对我有用。

关于java - 如何修复 "HTTP Status 500- Servlet exception threw an exception",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21346489/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com