Java 什么 JAR 包含 Part 类和 getPart() 方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19362214/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What JAR contains Part class and getPart() method?
提问by MDP
i was trying to follow this example http://www.codejava.net/coding/upload-files-to-database-servlet-jsp-mysqlto insert images into a blob field of a db.
我试图按照这个例子 http://www.codejava.net/coding/upload-files-to-database-servlet-jsp-mysql将图像插入到数据库的 blob 字段中。
I have problems on the line
我上线有问题
Part filePart = request.getPart("photo");
I get these errors:
我收到这些错误:
- Part cannot be resolved to a type
- The method getPart(String) is undefined for the type HttpServletRequest
I was trying to figure out what jar i should include but i didnt find nothing working good.
我试图弄清楚我应该包含什么罐子,但我没有发现任何效果很好。
If i use ctrl+shift+o on clipse it gives me two possibile packages:
如果我在 clipse 上使用 ctrl+shift+o,它会给我两个可能的包:
import com.sun.java.swing.plaf.windows.TMSchema.Part;
com.sun.xml.internal.ws.wsdl.writer.document.Part;
But no one of them seems to contain what i need
但似乎没有一个包含我需要的东西
If i try to import javax.servlet.http.Part i get this error
如果我尝试导入 javax.servlet.http.Part 我会收到此错误
The import javax.servlet.http.Part cannot be resolved
I still miss something.
我还是想念一些东西。
I installed TOMCAT 7, i imported javax.servlet.http.Part and now i have no error from eclipse. Thanks everybody
我安装了 TOMCAT 7,我导入了 javax.servlet.http.Part,现在我在 Eclipse 中没有错误。谢谢大家
采纳答案by ced-b
This depends to a large degree on the Servlet Container you are using. The tutorial mentions, that it uses Servlet API 3.0. If you are using Tomcat 6.0 for example it only supports up to 2.5 which does not seem to have the feature you are trying to use. Tomcat 7 on the other hand supports 3.0.
这在很大程度上取决于您使用的 Servlet 容器。该教程提到,它使用 Servlet API 3.0。例如,如果您使用的是 Tomcat 6.0,它最多只支持 2.5,这似乎没有您尝试使用的功能。另一方面,Tomcat 7 支持 3.0。
You could probably hack your servlet container by replacing the servlet-api.jar file with a newer version, but I would recommend upgrading.
您可能会通过用更新版本替换 servlet-api.jar 文件来破解您的 servlet 容器,但我建议升级。
回答by jama
Looking at the code on that page, I'd wager a guess that it's...
查看该页面上的代码,我打赌它是......
import javax.servlet.http.Part;
回答by user2571962
import javax.servlet.http.Part;
回答by Cem Sultan
You need the Java EE jar with the following import:
您需要具有以下导入的 Java EE jar:
import javax.servlet.http.Part;