问题描述
我正在学习如何制作一个servlet 3.1兼容的webapp,它将在JBoss wildfly 10上运行。我使用maven作为依赖项,我不确定以下依赖项的确切做法,以及是否包含/不包含它们在servlet容器中:
I'm learning how to make a servlet 3.1 compliant webapp, that will run on JBoss wildfly 10. I use maven for dependencies, and I'm unsure what the following dependencies do exactly, and if they are included/not included in the servlet container:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.version}</version>
</dependency>
我已经进行了一些谷歌搜索,希望验证或完成以下信息:
I already did some googling and would like verification or completion of the following information:
- servlet api由servlet容器提供,因此我可以添加
< scope>提供< / scope>
在Maven中。但是,为什么我需要包含这个罐子?删除后哪些类或文件会出错? - 我不确定javax.servlet.jsp-api是做什么的。如果我不包含它,我的hello world示例似乎运行得很好。这是做什么的?我是否需要添加
< scope>提供< / scope>
? - 任何servlet都不提供JSTL容器,所以必须明确添加。这个jar确保在我的jsp中正确处理
< c:xxx>
和其他基本标签。
- The servlet api is provided by the servlet container, so I can add
<scope>provided</scope>
in Maven. However, why do I need to include this jar? Which classes or files will have errors when I remove it? - I'm not sure what javax.servlet.jsp-api does. My hello world example seems to run just fine if I don't include it. What does this do? And do I need to add
<scope>provided</scope>
or not? - The JSTL is not provided by any servlet container, so it must be explicitly added. This jar ensures that the
<c:xxx>
and other basic tags are processed correctly in my jsp's.
推荐答案
标记提供的依赖项将使其可用于编译时和测试类路径,但不能用于运行时类路径 - 正如您所说的容器将提供实现这些API在运行时。
Marking a dependency as provided will make it available to the compile time and test classpaths but not to the runtime classpath - as you say the container will provide an implementation of these APIs at runtime.
-
如果您正在开发Web应用程序,则不太可能不使用类来自Servlet API(HttpServletRequest,HttpServletResponse,Filter等)。虽然许多框架抽象掉了大部分Servlet API,但仍然可能需要使用这些底层API。
If you are developing a web application it is unlikely you will be able to do without using classes from the Servlet API (HttpServletRequest, HttpServletResponse, Filter etc). While many frameworks abstract away much of the Servlet API it is still likely you will be required to work with these underlying API.
是的,添加范围。但是,如果您通过扩展say,javax.servlet.jsp.tagext.TagSupport创建自定义JSP标记,那么您只需要在编译时类路径中使用它(尽管标记文件提供了一种更现代的方法来创建自定义标记) 。
Yes, add scope provided. However you would only need this in the compile time classpath if, for example, you were creating a custom JSP tag by extending say, javax.servlet.jsp.tagext.TagSupport (although tag files provide a more modern way to create custom tags).
是和是。
这篇关于javax.servlet.jsp-api的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!