Get parameter from a POST
Having a problem with a servlet posting from a form:
// index.jsp
<FORM ENCTYPE='multipart/form-data' method='POST' action='/test/uploadfile'>
Your name: <input type="text" uploadername="name" /><br />
<INPUT TYPE='file' NAME='filetoupload'>
<INPUT TYPE='submit' VALUE='upload'>
</FORM>
// testservlet.java
protected void doPost(HttpServletRequest request, HttpServl开发者_JAVA技巧etResponse response)
throws ServletException, IOException
{
String name = req.getParameter("uploadername");
if (name == null || name.length() < 0) {
// seems to always be empty.
}
}
So yeah the name
parameter never seems to be sent. What am I doing wrong?
You want
<input type="text" name="uploadername" />
It would seem that what you're trying to do isn't support by the servlet API prior to version 3.0. See this question for details and possible solutions.
精彩评论