Pulling a form name as a parameter
Let's say I have the following HTML form:
<form name="createnewuser" action="verifyInfo.jsp"开发者_如何学Python>
... Contents of form here ...
</form>
In verifyInfo.jsp, is there a way to call the form's name (ideally as some kind of ${param} variable)?
To identify the submitted form, you can use:
- A hidden input field.
- The name or value of the submit button.
The name of the form is not sent to the server as part of the POST data.
<form id="form1">
<input type="submit" name="form1" value="Submit Form"/>
</form>
<form id="form2">
<input type="submit" name="form2" value="Submit Form"/>
</form>
Now either form1 or form2 will be sent as POST data containing the value text of the button.
Here is some code. Im not familiar with JSP but I think this is what you do O_O
if ( request.getParameter("form1") != null ) {
//Do stuff with form1
}
else if ( request.getParameter("form2") != null ) {
//Do stuff with form2
}
精彩评论