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

2
  • You need to put the html form code in a "code" tag or it won't display. Commented Sep 18, 2009 at 13:57
  • I've edited your post so that the form and scriptlet are marked as code. You can do this in the future by selecting the text, and clicking the "0101" button on top of the editing box. Commented Sep 18, 2009 at 14:00

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.