【问题标题】:http 500 error servlet java the duplicate Q&a dose not answer [duplicate]http 500错误servlet java重复的问答没有回答[重复]
【发布时间】:2016-06-25 17:48:18
【问题描述】:

我正在运行 tomcat 7。我在本地计算机上构建了 mysql db 当我尝试运行 jsp 文件时,我得到 HTTP 状态 404 或 HTTP 状态 500。 我在这里阅读了所有问答,但没有找到答案。 对不起,我是servlet的新手......

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  <display-name>todolistservlet</display-name>
  <welcome-file-list>
    <welcome-file> ToDoListLogin.jsp</welcome-file>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>login</servlet-name>
    <servlet-class>Controller</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>login</servlet-name>
    <url-pattern>/ToDoListLogin.jsp</url-pattern>
  </servlet-mapping>
</web-app>

ToDoListLogin.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
<title>To Do List Login Page</title>

    <!-- Bootstrap core CSS -->
    <link href="../css/bootstrap.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="../css/custom.css" rel="stylesheet">
</head>
<body background="./ToDoListWebPic/icon1.png" style="background-size:62%;">

    <%
    String authentication = (String)request.getSession().getAttribute("authentication");


    %>
        <div class="sign-container">
            <div class="container">
                <%
                    if (authentication != null && authentication == "false")
                    {
                %>
                        <div class="alert alert-danger" style="margin-top:0;">
                            <strong>user id and/or Password Incorrect!</strong>
                        </div>
                <%

                    }
                %>
                  <form action="loginServlet" method="get" class="form-signin">
                  <h1 class="form-signin-heading text-primary">Wellcom to MyToDoList </h1>
                    <h2 class="form-signin-heading text-primary">Please sign in</h2>

                    <label for="inputUserId" class="sr-only">user Id</label>
                    <input type="text" id="inputuserId" name="userId" class="form-control"  />
                    </div>
                    <div>
                    <label for="inputPassword" class="sr-only">Password</label>
                    <input type="password" id="inputPassword" name="password" class="form-control"  />

                    <div>
                        <button class="btn btn-primary btn-lg"  type="submit" onsubmit="EncryptorPass.encryptPassword(password)" >Sign in</button>
                        </div>
                        <div>
                        <a href="signup"  class="btn btn-default btn-lg">Sign Up</a>
                    </div>
                  </form>

            </div> <!-- /container -->

         </div>
  </body>
</html>`

loginServlet.java

package Controller;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
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 model.IToDoListDAO;
import model.ToDoListException;

/**
 * Servlet implementation class loginServlet
 */
@WebServlet("/loginServlet")
public class loginServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private IToDoListDAO dao = IToDoListDAO.getInstance();
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String encryptedPass = null;

        request.getSession().getAttribute("currentList");
        (String)request.getSession().getAttribute("currentItem");

        EncryptorPass.encryptPassword(request.getParameter("password"));
            boolean isUserExists;
            int user = Integer.parseInt(userId);
            try {
                RequestDispatcher rd = null;
                isUserExists = dao.UserAuthentication( user, pwd);
                if (isUserExists)
                {
//  set authentication credentials into session

                        request.getSession().setAttribute("fullName", dao.getAllUsers());

                    request.getSession().setAttribute("userId", request.getParameter("userId"));
                    response.sendRedirect("home");
                }
                else
                {
                    request.getSession().setAttribute("authentication", "false");
                    response.sendRedirect("ToDoListLogin");
                    rd = request.getRequestDispatcher("/errorpage.jsp");
                }
                rd.forward(request, response);

            } catch (ToDoListException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}

【问题讨论】:

    标签: jsp servlets web.xml


    【解决方案1】:

    放一放

    @WebServlet("/loginServlet")
    

    并从 web.xml 文件中删除

    <servlet>
        <servlet-name>login</servlet-name>
        <servlet-class>Controller</servlet-class>
      </servlet>
      <servlet-mapping>
        <servlet-name>login</servlet-name>
        <url-pattern>/ToDoListLogin.jsp</url-pattern>
      </servlet-mapping>
    

    【讨论】:

    • 您好,感谢您的快速回复,我很高兴。现在我得到 HTTP 状态 500 - 实例化 servlet 类类名称类型时出错 异常报告消息 实例化 servlet 类时出错 il.ac.hit.samples.sharon.orly.ToDoList.Controller 描述 服务器遇到一个内部错误,阻止它完成这个请求.异常 javax.servlet.ServletException: 实例化 servlet 类类名时出错
    • 嗨,现在我得到 HTTP 状态 500 - 无法为 JSP 编译类:类型异常报告消息无法为 JSP 编译类:描述服务器遇到内部错误,阻止它完成此请求。异常 org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: [31] in the generated java file:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-28
    • 1970-01-01
    • 2018-10-19
    • 2015-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多