Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple Servlet and Nullpointerexception (error 500)
    text
    copied!<p>I get following error after trying to launch my first servlet... what may be wrong? I am using proper method (get) and the same code works for my friend... is it possible to be tomcat's fault?</p> <pre><code>org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet Ciastko threw exception java.lang.NullPointerException </code></pre> <p>DOGET method:</p> <pre><code>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); } } </code></pre> <p>and here is index.html file:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt; &lt;title&gt;Tytuł&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form action="Ciastko" method="GET"&gt; &lt;p&gt;Login: &lt;/p&gt;&lt;input name="login" id="login" /&gt; &lt;p&gt;Hasło: &lt;/p&gt;&lt;input name="pass" id="pass" /&gt; &lt;input type="submit" value="Wyślij!" /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload