使用Servlet 3.0上传文件时,request.getParameter()仍然工作吗? [英] Does request.getParameter() still work when uploading files with Servlet 3.0?

查看:137
本文介绍了使用Servlet 3.0上传文件时,request.getParameter()仍然工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚阅读这个很好的答案 BalusC关于如何使用3.0 Servlet API上传文件。



我的问题是关于使用 request.getParameter()常见字段。例如,如果我的表单看起来像这样:
$ b

 < form action =/ upload method =postenctype =multipart / form-data> 
< fieldset>
< label for =description>档案描述:< / label>
< input type =textid =descriptionname =descriptionvalue =/>

< label for =uploadedFile>档案:< / label>
< input type =fileid =uploadedFilename =uploadedFile/>

< input type =submitvalue =发送/>
< / fieldset>
< / form>

按照BalusC的解释,我应该操作InputStream返回 part.getInputStream ()来获取说明字段的内容。这是为什么 ?我试图简单地调用 request.getParameter(description),它似乎工作正常。使用Tomcat 7.0.20。
$ b

感谢您的帮助。

解决方案


我试图简单地调用request.getParameter(description),它似乎很好。


事实上,这在Servlet 3.0规范中是这样规定的,但是直到最近才在Glassfish的早期版本中使用,尽管它是参考实现。这已被报告为并已在3.1.2中修复,超过2年后的第一个3.0版本。


I just read this great answer from BalusC about how to upload files with the 3.0 Servlet API.

My question is about the use of request.getParameter() for common fields. For example, if my form looks like this :

<form action="/upload" method="post" enctype="multipart/form-data">
    <fieldset>
        <label for="description">File description:</label>
        <input type="text" id="description" name="description" value="" />

        <label for="uploadedFile">File:</label>
        <input type="file" id="uploadedFile" name="uploadedFile" />

        <input type="submit" value="Send" />              
    </fieldset>
</form>

Following what BalusC explained, I should manipulate the InputStream returned by part.getInputStream() to get the content of the description field. Why is that ? I tried to simply call request.getParameter("description"), and it seems to work fine.

I use Tomcat 7.0.20.

Thanks for your help.

解决方案

I tried to simply call request.getParameter("description"), and it seems to work fine.

Indeed, this is specified as such in the Servlet 3.0 spec, but this did not work in earlier versions of Glassfish until recently, even though it's the reference implementation. This has been reported as Glassfish issue 16740 and has been fixed in 3.1.2, more than 2 years after the first 3.0 release.

这篇关于使用Servlet 3.0上传文件时,request.getParameter()仍然工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆