0

最初のサーブレットを起動しようとすると、次のエラーが表示されます...何が問題なのですか? 私は適切なメソッド (get) を使用していますが、同じコードが私の友人にも機能します... Tomcat のせいである可能性はありますか?

org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet Ciastko threw exception
java.lang.NullPointerException

DOGET メソッド:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws    ServletException, IOException {
    // TODO Auto-generated method stub

     response.setContentType("text/html;charset=UTF-8");
      HttpSession sesja = request.getSession(true);
      PrintWriter out = response.getWriter();
      String login = request.getParameter("login");
      String pass = request.getParameter("pass");
      if(login.isEmpty() || pass.isEmpty()){
           out.println("Brak sesji lub atrybutu.");
          } 

      if(login.equals("admin") || pass.equals("admin")){
           out.println("ADMIN");
          } 
      else{
       sesja.setAttribute("login", login);
       sesja.setAttribute("pass", pass);
      }



}

ここにindex.htmlファイルがあります:

<!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=UTF-8">
<title>Tytuł</title>
</head>
<body>
<form action="Ciastko" method="GET">
<p>Login: </p><input name="login" id="login" />
<p>Hasło: </p><input name="pass" id="pass" />

<input type="submit" value="Wyślij!" />
</form>
</body>
</html>
4

1 に答える 1

0

ServletRequest.getParameter

Returns the value of a request parameter as a String, or null if the parameter does not exist.

You're not checking your login/pass for null, which will make isEmpty crash if the parameters are not set.

于 2013-05-06T20:28:23.307 に答える