问题描述
我试图上传多个文件在servlet 3.0>。所以这是我的code.I geting在getSubmittedFileName()方法的错误。不知道why.Help !!
$ b $ pre $ protected $ doPost(HttpServletRequest请求,
HttpServletResponse响应)throws ServletException,IOException {
String description = request.getParameter(description); //获取
//< input
// type =text
// name =description>
Part filePart = request.getPart(file); //检索< input type =file
// name =file>
String fileName = Paths.get(filePart.getSubmittedFileName())
.getFileName()。toString(); // MSIE修复
InputStream fileContent = filePart.getInputStream();
// ...(在这里做你的工作)
}
我之前得到了这个问题。
有些人帮我找到了这个问题的根源,所以这里是我得到的解决方案:
在Java EE 7的DOC中,您可以看到'Interface Part'已经被添加到了Servlet 3.1以来的getSubmittedFileName方法中,并且从tomcat网站上可以看到,Tomcat 7实现了Servlet 3.0,所以我需要从Tomcat 7升级到Tomcat 8.0.x。
参考文献:
ul> I am trying to upload multiple files in servlet 3.0> .So this is my code.I am geting an error at getSubmittedFileName() method. Dont know why.Help!!
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String description = request.getParameter("description"); // Retrieves
// <input
// type="text"
// name="description">
Part filePart = request.getPart("file"); // Retrieves <input type="file"
// name="file">
String fileName = Paths.get(filePart.getSubmittedFileName())
.getFileName().toString(); // MSIE fix.
InputStream fileContent = filePart.getInputStream();
// ... (do your job here)
}
I got this problem before.Some guy helped me to find the root of this issue, so here is the solution I got:
In the DOC of Java EE 7 you can see that the 'Interface Part' has been added to it getSubmittedFileName method since Servlet 3.1, and from tomcat website you can see that Tomcat 7 implemented Servlet 3.0, so I needed to upgrade from Tomcat 7 to Tomcat 8.0.x.
References:
这篇关于类型Part的getSubmittedFileName()方法未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!