开发者

Get parameter from a POST

开发者 https://www.devze.com 2023-02-17 07:59 出处:网络
Having a problem with a servlet posting from a form: // index.jsp <FORM ENCTYPE=\'multipart/form-data\' method=\'POST\' action=\'/test/uploadfile\'>

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消