从POST获取参数

时间:2011-03-17 22:33:54

标签: servlets file-upload

从表单发布servlet时遇到问题:

// 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.
    }
}

所以,似乎永远不会发送name参数。我做错了什么?

2 个答案:

答案 0 :(得分:3)

你想要

<input type="text" name="uploadername" />

答案 1 :(得分:-2)

看起来你要做的事情不是3.0版之前的servlet API支持。有关详细信息和可能的解决方案,请参阅this question