0

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, HttpServletResponse 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?

skaffman
  • 398,947
  • 96
  • 818
  • 769
user291701
  • 38,411
  • 72
  • 187
  • 285
  • 1
    I dont know a thing about servlets however "name" is an html keyword try changing it to name1. – The_asMan Mar 17 '11 at 22:38
  • possible duplicate of [Convenient way to parse incoming multipart/form-data parameters in a Servlet](http://stackoverflow.com/questions/3337056/convenient-way-to-parse-incoming-multipart-form-data-parameters-in-a-servlet) – skaffman Mar 17 '11 at 22:42

2 Answers2

3

You want

<input type="text" name="uploadername" />
digitalsanctum
  • 3,261
  • 4
  • 29
  • 43
-2

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.

Community
  • 1
  • 1
brabster
  • 42,504
  • 27
  • 146
  • 186
  • This is entirely wrong and getting a form parameter is possible if you change the input element as I describe below. In the servlet req.getParameter should be request.getParameter. – digitalsanctum Mar 18 '11 at 14:00