mal*_*res 1 java servlets glassfish java-ee
在编写servlet时,我发现了一种方法
Since:
Servlet 3.1
Run Code Online (Sandbox Code Playgroud)
我想如果我有NetBeans的自动提示使用它是因为我有Servlet版本.但我找不到确认的地方.我使用glassfish4.1作为容器.如果我去mypathtoglassfish4.1\glassfish\modules
那里,我可以看到javax.servlet-api.jar
并在清单中说:
Implementation-Version: 3.1.0
Run Code Online (Sandbox Code Playgroud)
这是检查的正确方法吗?我特别感兴趣的是能够告诉我的同事"去那个罐子检查那个属性"所以我确信我的代码将在他们的服务器上运行.
作为替代方案,我找到了一个网页Oracle GlassFish Server 3.1应用程序开发指南,其中说:"GlassFish Server支持Java Servlet规范3.0版." 但很明显对于Glassfish 3.1而言,我找不到每种玻璃鱼版本中的一种(甚至不是我的-4.1)
看看Java EE版本.Servlet(以及JSP,JSF,EJB,JPA等)版本与Java EE版本密切相关.
查看服务器主页/文档如何呈现自己.对于GlassFish,目前(4.1):
世界上第一个Java EE 7应用服务器
所以,它是Servlet 3.1.
但是,有一个很大但是,这是一回事.第二件事是,webapp的web.xml
版本也起了作用.不是每个人都知道.
如果您的webapp web.xml
声明符合Servlet 3.1,如下所示,
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<!-- Config here. -->
</web-app>
Run Code Online (Sandbox Code Playgroud)
那么你的webapp也将真正运行在Servlet 3.1中.
但是,如果它声明符合Servlet 3.0,如下所示甚至更旧,
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<!-- Config here. -->
</web-app>
Run Code Online (Sandbox Code Playgroud)
然后你的webapp将在Servlet 3.0兼容性模式下运行,即使部署到Servlet 3.1兼容容器!以上影响ServletContext#getMajorVersion()
和getMinorVersion()
,所以他们实际上没有说容器,但只关于webapp本身.
如果您的webapp web.xml
包含一个<!DOCTYPE>
,无论DTD和版本如何,那么它将以Servlet 2.3兼容性模式运行,即使声明有更新的XSD!
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "java.sun.com/dtd/web-app_2_3.dtd">
<web-app
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<!-- This is WRONG! The DOCTYPE must be removed! -->
</web-app>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5463 次 |
最近记录: |