sheetal
sheetal

Reputation: 199

Getting a null value,where a value is expected

I am trying to create a Login page using JSP.The first Jsp page collects the username and password, when login button is pressed the user is navigated to another JSP page.Here I want to display the username of the user.I wrote a code for it,but I am getting null as the value.Kindly tell me where I have gone wrong.The code is as follows

Login.jsp

  <body>
  <center>
  <b>LOGIN PAGE</b><br>
  </center>
  <form name="login" method="post" action="HomePage.jsp">
  <center>
  USER NAME: <input type="text" name="username"> <br>
  <br>
  PASSWORD: <input type="password"> <br>
  <br> 
  <input type="button" value="LOGIN" onclick="window.location.href='HomePage.jsp'">
  </center>
  </form>
  </body>

And here is my HomePage.jsp

  <body>
  WELCOME
  <%
  String Uname=request.getParameter("username");
  out.println(Uname);
  %>
  </body>

Upvotes: 0

Views: 113

Answers (2)

Rohith K
Rohith K

Reputation: 1492

The form submission to the servlet can be done only by 2 ways, Submit using a input type ="Submit" or Using javascript submit() function needs to be called.

Upvotes: 0

darkled
darkled

Reputation: 257

It looks like you need type="submit" instead of button.

Upvotes: 3

Related Questions