title: Create a sample login page using servlet and JSP?
body: <p>I developed a sample login page for validating username and password. If the user gives correct credentials the page will navigate to some other page, else return a message from the <code>servlet</code> to the same login page.</p>
  <p>I have enclosed the sample <code>code</code> here:</p>
  <h3>FirstJSP.jsp</h3>
  <pre><code>&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=ISO-8859-1&quot;
      pageEncoding=&quot;ISO-8859-1&quot;%&gt;`
  &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org   /TR/html4/loose.dtd&quot;&gt;`
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot;&gt;
          &lt;title&gt;Insert title here&lt;/title&gt;`
      &lt;/head&gt;
      &lt;body&gt;
          &lt;form action=&quot;Login&quot; method=&quot;post&quot;&gt;
              &lt;input type=&quot;text&quot; name=&quot;Name&quot;/&gt;&lt;br&gt;
              &lt;input type=&quot;password&quot; name=Pass&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;
              &lt;input type=&quot;submit&quot; value=&quot;submit&quot;/&gt;&lt;br&gt;
              &lt;%if(request.getAttribute(&quot;message&quot;)!=(&quot;&quot;))
              out.println(request.getAttribute(&quot;message&quot;));
              else
              out.println(&quot;&quot;);%&gt;
              &lt;h1&gt;Hi This is JSP sample code &lt;/h1&gt;
              &lt;font color=&quot;blue&quot; size=&quot;25&quot;&gt;
              &lt;marquee&gt;Please login to Work with JSP&lt;/marquee&gt;&lt;/font&gt;
              &lt;%java.text.DateFormat df = new java.text.SimpleDateFormat(&quot;MM/dd/yyyy&quot;); %&gt;
              &lt;h1&gt;Current Date: &lt;%= df.format(new java.util.Date()) %&gt; &lt;/h1&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>And <code>servlet</code> code, Login.java:</p>
  <pre><code>package com.controller;
  import java.io.IOException;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  public class Login extends HttpServlet {
      private static final long serialVersionUID = 1L;
      
      public Login() {
          super();
      }
      
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          String username = request.getParameter(&quot;Name&quot;);
          String password = request.getParameter(&quot;Pass&quot;);
          response.setContentType(&quot;text/html&quot;);
          if(username.equals(&quot;sugan&quot;) &amp;&amp; password.equals(&quot;raj&quot;)) {
              response.getWriter().println(&quot;&lt;html&gt;&lt;body&gt;&lt;Marquee&gt;Welcome to JSP!!!&lt;/marquee&gt;&lt;/body&gt;&lt;/html&gt;&quot;);                
          } 
          else {                
              String message = &quot;OOps!!! Invalid Username/Password&quot;;
              request.setAttribute(&quot;message&quot;, message);
              request.getRequestDispatcher(&quot;/FirstJSP.jsp&quot;).forward(request, response);                
          }
      }
  }
  </code></pre>
  <p>It works fine, but while loading the login page it automatically displays <code>Null</code>. Then if the user gives the wrong credentials, it displays the actual message. How do I disable the <code>Null</code> message during run time?</p>