日期:2014-05-17  浏览次数:20754 次

Servlet取得页面参数为何为空
我的From:
  <form name="formwq" action="FileUploadServlet" method="post" enctype="multipart/form-data">
 <p align="center">
 <input type="file" size="30" name="test"/>
 <br/>
 <input name="configFT" type="hidden" value="<%=configFT%>"/>
 <input name="up" type="submit" value="上传"/>
 <input name="goback1" type="button" value="返回" onClick="goConfigList()"/>
  </p>
 </form>

我的doPost:
  public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String configFT = request.getParameter("configFT");
System.out.println(configFT);
}

我的web.xml
  <servlet>
  <servlet-name>FileUploadServlet</servlet-name>
  <servlet-class>com.adtec.moiaone.iias.config.FileUploadServlet</servlet-class>
  </servlet>

  <servlet-mapping>
  <servlet-name>FileUploadServlet</servlet-name>
  <url-pattern>/wqtest/configjsp/FileUploadServlet</url-pattern>
  </servlet-mapping>

我是想上传文件,configFT参数指定上传的文件夹。上传文件实现了,configFT却取不到。高手指教。

------解决方案--------------------
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (item.isFormField())
{
if (item.getFieldName().equals("表单域的名"))
{
String hidden = item.getString();
}
}
//忽略其他不是文件域的所有表单信息
if (!item.isFormField()) {
String name = item.getName();
long size = item.getSize();
if((name==null||name.equals("")) && size==0)
continue;
// 注意item.getName()
// 会返回上载文件在客户端的完整路径名称,这似乎是一个BUG。
// 为解决这个问题,这里使用了fullFile.getName()。
name=name.replace('\\','/');
File fullFile = new File(name); 

File savedFile = new File(filepath,fullFile.getName());
item.write(savedFile);
msg="<img alt='"+fullFile.getName()+"' src='"+updir+curdate+"/"+fullFile.getName()+"' />";
img="<img alt='"+fullFile.getName()+"' src='"+updir+curdate+"/"+fullFile.getName()+"' />";
}
 }
}//opmsg=null

------------------
只有这样才可以获取.
if (item.isFormField())
{
if (item.getFieldName().equals("表单域的名"))
{
String hidden = item.getString();
}
}

multipart/form-data因为你加了这个类型.