title: Values of variables received as null in JSP page
body: <p>I have made a simple login app. But the servlet receives null data whenever the form is sent.</p>
  
  <p>Below is login page</p>
  
  <pre><code>&lt;body&gt;
  &lt;form action="login"&gt;
      Enter login Name : &lt;input type="text" name="userName"/&gt;&lt;br/&gt;
      Enter password   : &lt;input type="password" name="userPassword"/&gt;&lt;br/&gt;
      &lt;input type="submit" value="Log In"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p></p>
  
  <p>The below is the servlet code to check the values of variable entered</p>
  
  <pre><code>@WebServlet("/login")
  public class loginServlet extends HttpServlet {
  private static final long serialVersionUID = 1L;
  
  /**
   * @see HttpServlet#HttpServlet()
   */
  public loginServlet() {
      super();
      // TODO Auto-generated constructor stub
  }
  
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      String name = (String)request.getAttribute("userName");
      String password = (String)request.getAttribute("userPassword");
  
      System.out.print("in doGet method");
      System.out.print(name+" "+password+" are these");
  
  
      if(name!=null &amp;&amp; password!=null){
          System.out.print("in null method");
          if(name=="admin" &amp;&amp; password=="admin"){
  //              Cookie cookie = new Cookie("userName", name);
  //              response.addCookie(cookie);
  //              RequestDispatcher dispatch = request.getRequestDispatcher("success.jsp");
  //              dispatch.forward(request, response);
  
              response.sendRedirect("success.jsp");
          }
          else{
              System.out.print("in error method");
              response.sendRedirect("error.jsp");
          }
      }
  }
  
  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I am using System.out.print method to print the values in Tomcat console.</p>