I am working on a JSP file(don't want to use a servlet), I have a simple form, 2 labels, 2 inputs and 2 buttons, and I want to print out the submitted string on the same jsp page , the problem is that the last values submitted remain printed on the screen as I try new ones, that is why I thought of a test to check whether the button submit was clicked before we move to the display, I tried this code :
<body>
<form method='post'>
<pre>
<label>Username</label> <input type="text" name="user" required/>
<label>Password</label> <input type="password" name="pwd" required />
<br>
<input type="submit" value="confirm" name ="submit" />
<input type="reset" value="clear" />
</pre>
</form>
<br>
// test if the submit button was clicked (check if value of submit is confirm)
<% String x=request.getParameter("submit")%>
<% if (x.equals("confirm")){ %>
<% if (request.getParameter("user")!="" && request.getParameter("pwd")!=""){ %>
<center>
<h4> user is : <% out.write(request.getParameter("user")); %> </h4>
<br>
<h4> password is : <% out.write(request.getParameter("pwd")); %> </h4>
</center>
<% } else { %>
<h4> inputs r empty !! </h4>
<% } %>
<% } %>
</body>
I get an error at line :
<% if (x.equals("confirm")){ %>
any idea why ?