I have the following form setup:
<html>
<head></head>
<body>
<form method="post" enctype="multipart/form-data" action="FileUpload">
<table>
<th>WEX SI Online Validation</th>
<tr>
<td>Step 1: Select File for Validation: </td>
<td><input name="filename" type="file"/></td>
</tr>
<tr>
<td>Step 2: Validate File:</td>
<td><input name="validate" type="button" value="Validate"/></td>
</tr>
<tr>
<td>Step 3: Download and Fix Errors:</td>
<td><input name="download" type="button" value="Download"/></td>
</tr>
<tr>
<td>Step 4: Submit</td>
<td><input name="submit" type="submit" value="Submit"/></td>
</tr>
</table>
</form>
</body>
</html>
How should I handle this? I’m using Java/JSP/Servlets but am not sure how to handle the post for the upload portion of this and than the other actions.
I think it would be best to create some kind of form controller that handled the post of the form and delegated to other servlets depending on what the user is doing. I’m not sure how to tell what the user has selected though.
As for every other normal
<input>element, thename-valuepair of a<input type="button">will be sent as request parameter.The major caveat is only that
<input type="button">and<button>elements does not work properly in MSIE. In all MSIE versions, thevalueattribute of a button element won’t be sent as parameter value, but instead its body (the tag content) will be sent!Also, in IE6 there’s another astonishing bug: not only the name-value pair of the pressed button will be sent, but those of every other unpressed button in the form will be sent as well! This way you cannot distinguish the pressed button in the server side at all.
The solution which works in combination with all browsers is to use
<input type="submit">and to give them all a different name (or the same name but a different value).E.g.
in combination with
or
in combination with
The last way provides more possibilities to abstract the one and other more nicely away at Java level.
By the way, I of course assume that you’re already using Apache Commons FileUpload to process the multipart form data, if necessary with help of a Filter which puts the multipart form data back in the request parameter map, else you won’t get anything from
HttpServletRequest#getParameter().