tags:

views:

349

answers:

1

In my jsp code I use the request.getParameter() to retrieve the data which is entered in html. The data was retrieved when using get method but it is not when im using post method Why this happend

My html form is

<code>
<form  name="inp" action="upload.jsp"  method="post" onsubmit="return valid();" enctype="multipart/form-data">
<table align="center" cellspacing="2">

<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td><font size="5" color="#E41B17">Select File</font> </td>
<td><input type="file" name="infile"></td>
</tr>
<tr><td><font size="5" color="#E41B17">Target File Name</font></td>
<td><input type="text" size="20" name="filename"></input></td>
</tr>
<tr></tr>
<tr><td colspan="2" align="center"><input type=submit value="Upload"  ></td></tr>
</table>
<br></br>
<center>
<a href="index.html"><font color="#E41B17">HOME</font></a>
</center>
</form>
</code>

And my jsp scriptlet is

<% String f = request.getParameter("filename");
  System.out.println(f); %>

Thanks in Advance

+5  A: 

Now to the issues: you've set the form's content type to be multipart, which means that you have to explicitly parse the request body; the container will only parse if you leave the default form-encoded. This article seems to give an example of how to access multipart data on the server side.

Aside from that, you do realize that your form is commented-out, so should never be handled by your browser, right? If you're actually seeing something on the browser, it probably isn't coming from this location.

kdgregory
I would add that if you don't need to "manually" parse the POST stream, then removing the encoding will resolve the immediate problem.
shrub34