Two forms but only 1 jsp file
- by joshft91
Here's what I've got going on. I have one .jsp file. However, I have two forms with multiple inputs inside those forms.
What is the best way to detect that one form was submitted but not the other? Here's an example: I have this form:
<form name = "login" action="index.jsp" method="get">
Username: <input id="username" name="username" type="text"/><br/>
Password: <input id="password" name="password" type="password"/>
<input type="submit" Value="Login" ></input>
</form>
If that button is clicked, I'd like to run this code:
String username = request.getParameter("username");
String password = request.getParameter("password");
if((username!= null && !username.trim().equals("")) && (password != null && !username.trim().equals(""))) {
DBentry DBentry=new DBentry();
boolean flag = DBentry.isTaken(username);
if(flag) {%><script type="text/javascript">alert("Login Successful!");</script><%
}
else { %><script type="text/javascript">alert("Unrecognized username. Please register!");</script><% }
}
else { %><script type="text/javascript">alert("Please enter both a username and password!");</script><% }
Further down I would have something exactly like it but submitting a different form.
Thanks!