我在servlet中给出了错误

时间:2016-11-11 10:39:27

标签: java servlets

我想检查授权用户/不在SERVLET中。 的的login.html

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Login page</title>
</head>
<body>
<table>
</table>
<form action="Check.java" >
USERNAME:<input type="text" value="name"><br><br>
PASSWORD:<input type="password" value="password"><br><br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp<button style="color: #ff3399">SUBMIT</button>
</form>
</body>
</html>

Check.java

import java.io.*;  
import javax.servlet.*;  
import javax.servlet.http.*;  


public class Check extends HttpServlet {  

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

    response.setContentType("text/html");  
    PrintWriter out = response.getWriter();  

    String n=request.getParameter("name");  
    String p=request.getParameter("password");  

    if(p.equals("servlet")){  
        RequestDispatcher rd=request.getRequestDispatcher("servlet2");  
        rd.forward(request, response);  
    }  
    else{  
        out.print("Sorry UserName or Password Error!");  
        RequestDispatcher rd=request.getRequestDispatcher("/Login.html");  
        rd.include(request, response);  
    }
        }  
}  

WelcomeServlet.java

import java.io.*;  
import javax.servlet.*;  
import javax.servlet.http.*;  

public class WelcomeServlet extends HttpServlet {  

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

    response.setContentType("text/html");  
    PrintWriter out = response.getWriter();  

    String n=request.getParameter("name");  
    out.print("Welcome "+n);  
    }  

}

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" id="WebApp_ID" version="3.0">

<display-name>REALPROJECT</display-name>
 <servlet>  
    <servlet-name>Check</servlet-name>  
    <servlet-class>Check</servlet-class>  
  </servlet>  
  <servlet>  
    <servlet-name>WelcomeServlet</servlet-name>  
    <servlet-class>WelcomeServlet</servlet-class>  
  </servlet>  


  <servlet-mapping>  
    <servlet-name>Check</servlet-name>  
    <url-pattern>/servlet1</url-pattern>  
  </servlet-mapping>  
  <servlet-mapping>  
    <servlet-name>WelcomeServlet</servlet-name>  
    <url-pattern>/servlet2</url-pattern>  
  </servlet-mapping>  

  <welcome-file-list>  
   <welcome-file>Login.html</welcome-file>  
  </welcome-file-list>  
</web-app> 

我的错误是:

HTTP状态500 -

输入例外报告

消息

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

例外

java.lang.NullPointerException
    Check.doPost(Check.java:17)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

注意Apache Tomcat / 7.0.70日志中提供了根本原因的完整堆栈跟踪。

0 个答案:

没有答案