javax.servlet 在哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/860022/
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
Where's javax.servlet?
提问by egaga
I have jdk1.6.0_13
installed, but when I try to find a javax.servlet
package, or press Ctrl+Spacein Eclipse after Servlet
I cannot get anything. Where can I download this package, and why isn't it included in standard distribution for developers?
我已经jdk1.6.0_13
安装了,但是当我尝试查找javax.servlet
软件包时,或者在找不到任何东西后在 Eclipse 中按Ctrl+ 。我在哪里可以下载这个包,为什么它没有包含在开发人员的标准发行版中?SpaceServlet
采纳答案by Joachim Sauer
javax.servlet
is a package that's part of Java EE (Java Enterprise Edition). You've got the JDK for Java SE (Java Standard Edition).
javax.servlet
是 Java EE(Java 企业版)的一部分的包。您已经获得了 Java SE(Java 标准版)的 JDK。
You could use the Java EE SDKfor example.
例如,您可以使用Java EE SDK。
Alternatively simple servlet containers such as Apache Tomcatalso come with this API (look for servlet-api.jar
).
或者,简单的 servlet 容器(例如Apache Tomcat)也带有此 API(查找servlet-api.jar
)。
回答by Decio Lira
回答by KingInk
those classes are usually part of servlet.jar
http://www.java2s.com/Code/Jar/wsit/Downloadservletjar.htm
这些类通常是 servlet.jar http://www.java2s.com/Code/Jar/wsit/Downloadservletjar.htm 的一部分
回答by BalusC
The normal procedure with Eclipse and Java EE webapplications is to install a servlet container (Tomcat, Jetty, etc) or application server (Glassfish (which is bundled in the "Sun Java EE" download), JBoss AS, WebSphere, Weblogic, etc) and integrate it in Eclipse using a (builtin) plugin in the Serversview.
Eclipse 和 Java EE web 应用程序的正常过程是安装 servlet 容器(Tomcat、Jetty 等)或应用程序服务器(Glassfish(捆绑在“Sun Java EE”下载中)、JBoss AS、WebSphere、Weblogic 等)并使用服务器视图中的(内置)插件将其集成到 Eclipse 中。
During the creation wizard of a new Dynamic Web Project, you can then pick the integrated server from the list. If you happen to have an existing Dynamic Web Projectwithout a server or want to change the associated one, then you need to modify it in the Targeted Rutimessection of the project's properties.
在新动态 Web 项目的创建向导期间,您可以从列表中选择集成服务器。如果您碰巧有一个没有服务器的现有动态 Web 项目或想要更改关联的项目,那么您需要在项目属性的Targeted Rutimes部分修改它。
Either way, Eclipse will automatically place the necessary server-specific libraries in the project's classpath (buildpath).
无论哪种方式,Eclipse 都会自动将必要的特定于服务器的库放置在项目的类路径(构建路径)中。
You should absolutely in no wayextract and copy server-specific libraries into /WEB-INF/lib
or even worse the JRE/lib
yourself, to "fix" the compilation errors in Eclipse. It would make your webapplication tied to a specific server and thus completely unportable.
您绝对不应该将特定于服务器的库提取并复制到您自己中,/WEB-INF/lib
甚至更糟JRE/lib
,以“修复”Eclipse 中的编译错误。它会使您的 web 应用程序绑定到特定的服务器,因此完全不可移植。
回答by Teemu Leisti
A bit more detail to Joachim Sauer's answer:
约阿希姆绍尔回答的更多细节:
On Ubuntu at least, the metapackage tomcat6
depends on metapackage tomcat6-common
(and others), which depends on metapackage libtomcat6-java
, which depends on package libservlet2.5-java
(and others). It contains, among others, the files /usr/share/java/servlet-api-2.5.jar
and /usr/share/java/jsp-api-2.1.jar
, which are the servlet and JSP libraries you need. So if you've installed Tomcat 6 through apt-get or the Ubuntu Software Centre, you already have the libraries; all that's left is to get Tomcat to use them in your project.
至少在 Ubuntu 上,元包tomcat6
依赖于元包tomcat6-common
(和其他),元包依赖于元包libtomcat6-java
,元包依赖于包libservlet2.5-java
(和其他)。其中包含文件/usr/share/java/servlet-api-2.5.jar
和/usr/share/java/jsp-api-2.1.jar
,它们是您需要的 servlet 和 JSP 库。因此,如果您已经通过 apt-get 或 Ubuntu 软件中心安装了 Tomcat 6,那么您已经拥有了这些库;剩下的就是让 Tomcat 在您的项目中使用它们。
Place libraries /usr/share/java/servlet-api-2.5.jar
and /usr/share/java/jsp-api-2.1.jar
on the class path like this:
将库/usr/share/java/servlet-api-2.5.jar
和/usr/share/java/jsp-api-2.1.jar
类放在这样的路径上:
For all projects, by configuring Eclipse by selecting Window -> Preferences -> Java -> Installed JREs, then selecting the JRE you're using, pressing Edit, then pressing Add External JARs, and then by selecting the files from the locations given above.
For just one project, by right-clicking on the project in the Project Explorer pane, then selecting Properties -> Java Build Path, and then pressing Add External JARs, and then by selecting the files from the locations given above.
对于所有项目,通过选择 Window -> Preferences -> Java -> Installed JREs 来配置 Eclipse,然后选择您正在使用的 JRE,按 Edit,然后按 Add External JARs,然后从上面给出的位置选择文件.
对于一个项目,右键单击 Project Explorer 窗格中的项目,然后选择 Properties -> Java Build Path,然后按 Add External JARs,然后从上面给出的位置选择文件。
Further note 1: These are the correct versions of those libraries for use with Tomcat 6; for the other Tomcat versions, see the table on page http://tomcat.apache.org/whichversion.html, though I would suppose each Tomcat version includes the versions of these libraries that are appropriate for it.
进一步说明 1:这些是用于 Tomcat 6 的库的正确版本;对于其他 Tomcat 版本,请参阅http://tomcat.apache.org/whichversion.html页面上的表格,但我认为每个 Tomcat 版本都包含适合它的这些库的版本。
Further note 2: Package libservlet2.5-java
's description (dpkg-query -s libservlet2.5-java
) says: 'Apache Tomcat implements the Java Servlet and the JavaServer Pages (JSP)specifications from Sun Microsystems, and provides a "pure Java" HTTP web server environment for Java code to run. This package contains the Java Servlet and JSP library.'
进一步说明 2:包libservlet2.5-java
的描述 ( dpkg-query -s libservlet2.5-java
) 说: 'Apache Tomcat 实现了Sun Microsystems的Java Servlet 和 JavaServer Pages (JSP)规范,并为 Java 代码的运行提供了一个“纯 Java”HTTP Web 服务器环境。这个包包含 Java Servlet 和 JSP 库。
回答by fundead
If you've got the Java EE JDK with Glassfish, it's in glassfish3/glassfish/modules/javax.servlet-api.jar.
如果您有带有 Glassfish 的 Java EE JDK,它位于 glassfish3/glassfish/modules/javax.servlet-api.jar 中。