简体   繁体   English

Java EE 7中的Servlet,JSP和JSTL需要哪些maven依赖项?

[英]What maven dependencies needs for Servlet, JSP and JSTL in Java EE 7?

I want use SDK Java EE 7, Glassfish 4 and Maven. 我想使用SDK Java EE 7,Glassfish 4和Maven。
Is it correct? 这是正确的吗? Please, draw attention to scopes. 请注意范围。

1. For servlets: 1.对于servlet:

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>7.0</version>
    <scope>provided</scope>
</dependency>

2. JSP without standart tags and without JSTL: 2.没有标准标签且没有JSTL的JSP:

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>jsp-api</artifactId>
  <version>2.0</version>
</dependency>

3. For JSP with standard tags "c:" 3.对于带有标准标签的JSP“c:”

<dependency>
    <groupId>taglibs</groupId>
    <artifactId>standard</artifactId>
    <version>1.1.2</version>
</dependency>

4. For JSP with JSTL 4.对于带有JSTL的JSP

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
    <scope>runtime</scope>
</dependency>

Do you know specification where this information contains? 您知道此信息包含的规范吗?

There are a variety of options. 有多种选择。 As suggested in the question, one approach is to import the whole Java EE API. 正如问题中所建议的,一种方法是导入整个Java EE API。 But you can also be more selective. 但你也可以更有选择性。 You can instead just include the servlet API (this is for servlet API 3.0.1; more recent versions are available for the same artifact data, but older versions use the artifact id servlet-api instead): 您可以只包含servlet API(这适用于servlet API 3.0.1;更新的版本可用于相同的工件数据,但旧版本使用工件ID servlet-api代替):

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
        <scope>provided</scope>
    </dependency>

The question implies that the JSTL package also pulls in the relevant JSP dependencies; 问题意味着JSTL包还引入了相关的JSP依赖关系; this isn't the case: if you need to use the JSP API at all, you do need a dependency for it (but it's worth noting that you don't necessarily need it, as discussed at this question ). 情况并非如此:如果您需要使用JSP API,则需要依赖它(但值得注意的是, 您不一定需要它,如本问题所述 )。 You should use the correct version of the JSP API that matches the Servlet API version you're using , so for servlet API 3.0.1 as I show above, you should use 2.2: 您应该使用与您正在使用的Servlet API版本匹配的正确版本的JSP API ,因此对于上面显示的servlet API 3.0.1,您应该使用2.2:

    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.2</version>
        <scope>provided</scope>
    </dependency>

Like for the Servlet API, there have been changes in the dependency data for the JSP API; 与Servlet API一样,JSP API的依赖数据也发生了变化。 in this case for versions older than 2.0 the group id is just javax.servlet , while for versions newer than 2.2 the artifact id has changed to javax.servlet.jsp-api . 在这种情况下,对于早于2.0的版本,组ID只是javax.servlet ,而对于比2.2更新的版本,工件id已更改为javax.servlet.jsp-api

For JSTL, you should almost certainly just be using version 1.2. 对于JSTL,您几乎肯定会使用1.2版本。 The new standard location for this version is: 此版本的新标准位置为:

    <dependency>
        <groupId>javax.servlet.jsp.jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

although the old location as shown in the question continues to work correctly. 虽然问题中显示的旧位置继续正常工作。 Presumably, should any future updates be made to this library they will be included with this group/artifact ID, as this appears to be designed to fit appropriately with all the other most recent artifacts. 据推测,如果将来对此库进行任何更新,它们将包含在此组/工件ID中,因为它似乎旨在适合所有其他最新工件。 Unlike the other artifacts, JSTL is not provided by the container, so the scope should not be set to "provided" as for the others. 与其他工件不同,容器不提供JSTL,因此范围不应设置为“提供”,而不是其他工件。

You shouldn't be adding these dependencies to your project. 您不应该将这些依赖项添加到项目中。 Instantiations of the J2EE specification such as servlets should be provided by the application server's runtime. J2EE规范的实例化(例如servlet)应由应用程序服务器的运行时提供。

In Eclipse, To add the Server Runtime for your application server. 在Eclipse中,为应用程序服务器添加服务器运行时。 Right click the project and select Properties. 右键单击项目,然后选择“属性”。 Then Build Path > Add Library > Server Runtime. 然后构建路径>添加库>服务器运行时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 终极Java版本表(J2EE、Java EE、Servlet、JSP、JSTL) - The ultimate Java version table (J2EE, Java EE, Servlet, JSP, JSTL) Tomcat 5.5 Servlet / JSP / JSTL依赖关系 - Tomcat 5.5 Servlet/JSP/JSTL dependencies 将项目集合从jsp发送到Java EE应用程序中的servlet的最佳方法是什么? - What's the best approach to send collection of item from jsp to a servlet in a Java EE application? Java EE 5 API的单个/完整Maven依赖项 - Single/complete Maven dependencies for Java EE 5 API Java EE 6中JSTL的状态 - Status of JSTL in Java EE 6 Java EE servlet的(内存)占用空间是多少? - What's the (memory) footprint of a Java EE servlet? Java JSTL错误java.lang.NoClassDefFoundError:javax / servlet / jsp / jstl / core / LoopTag - Java JSTL Error java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/LoopTag 安全框架,例如针对Java EE的接缝-JSP,Servlet,DAO - Security Framework like seam for Java EE - JSP, Servlet, DAO javax.servlet.ServletException:java.lang.NoClassDefFoundError:javax / servlet / jsp / jstl / core / ConditionalTagSupport - javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/ConditionalTagSupport 非Java EE 5 servlet和Java EE 5 servlet容器之间有什么区别? - what are differences between the non-Java EE 5 servlet and Java EE 5 servlet containers?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM