Two forms but only 1 jsp file

Posted by joshft91 on Stack Overflow See other posts from Stack Overflow or by joshft91
Published on 2012-09-19T03:27:26Z Indexed on 2012/09/19 3:37 UTC
Read the original article Hit count: 128

Filed under:
|
|
|

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!

© Stack Overflow or respective owner

Related posts about java

Related posts about html