开发者

Pulling a form name as a parameter

开发者 https://www.devze.com 2023-03-14 21:25 出处:网络
Let\'s say I have the following HTML form: <form name=\"createnewuser\" action=\"verifyInfo.jsp\"开发者_如何学Python>

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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号