如何找到glassfish服务器的servlet API版本? [英] How to find servlet API version for glassfish server?

查看:111
本文介绍了如何找到glassfish服务器的servlet API版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写一个servlet时,我发现一个方法说:

 从以下版本开始:
Servlet 3.1

我猜如果我有NetBeans的autohint来使用它,那是因为我有那个Servlet版本。但是我找不到一个地方来证实这一点。我使用glassfish4.1作为容器。如果我去 mypathtoglassfish4.1 \glassfish\modules 那里可以看到 javax.servlet-api.jar 并在一个清单里面写着:

  Implementation-Version:3.1.0 

这是检查的正确方法吗?我特别感兴趣的是能够告诉我的同事去那个jar并检查该属性,所以我确信我的代码将在他们的服务器上运行。



另外,我找到了一个网页 Oracle GlassFish Server 3.1应用程序开发指南表示:GlassFish服务器支持Java Servlet规范版本3.0。但对于Glassfish 3.1显然是这样,我找不到每个glassfish版本的一个(甚至不是我的-4.1版本)

解决方案

<阅读 Java EE版本。 Servlet(以及JSP,JSF,EJB,JPA等)版本与Java EE版本并行。


  • Java EE 8 = Servlet 4.0

  • Java EE 7 = Servlet 3.1
  • Java EE 6 = Servlet 3.0

  • Java EE 5 = Servlet 2.5

  • J2EE 1.4 = Servlet 2.4

  • J2EE 1.3 = Servlet 2.3

  • J2EE 1.2 = Servlet 2.2



查看服务器主页/文档是如何呈现的。对于 GlassFish ,目前(含4.1):



< blockquote>

全球首个Java EE 7应用服务器


所以,它是Servlet 3.1。



但是,有一个很大的,那是一回事。第二件事是,webapp的 web.xml 版本也扮演了角色。并不是每个人都知道。

如果您的webapp的 web.xml 被声明符合以下的Servlet 3.1,那么

<?xml version =1.0encoding =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>

<! - - 在这里配置。 - >
< / web-app>

然后你的web应用程序也将真正运行在Servlet 3.1模式中。



但是,如果声明符合Servlet 3.0,如下所示,甚至更老,
$ b

 <?xml version =1.0encoding =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>

<! - - 在这里配置。 - >
< / web-app>

然后,您的webapp将运行在Servlet 3.0兼容性模式下,即使部署到Servlet 3.1兼容容器!上面的例子影响了 ServletContext#getMajorVersion() getMinorVersion(),所以他们实际上对容器一无所知,如果你的webapp的 web.xml 包含一个< / code> !DOCTYPE> ,无论DTD和版本如何,那么它将以Servlet 2.3兼容方式运行,即使有更新的XSD声明!



< pre class =lang-xml prettyprint-override> <?xml version =1.0encoding =UTF-8?>
<!DOCTYPE web-app PUBLIC - // Sun Microsystems,Inc. //DTD Web Application 2.3 // ENjava.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>

<! - 这是错误的! DOCTYPE必须删除! - >
< / web-app>


While coding a servlet I found a method that says

Since:
    Servlet 3.1

I guess that if I have the autohint from NetBeans to use it is because I have that Servlet version. But I cannot find a place to confirm that. I'm using glassfish4.1 as container. If I go to mypathtoglassfish4.1\glassfish\modules there I can see javax.servlet-api.jar and inside a manifest that says:

Implementation-Version: 3.1.0

Is that the proper way to check that? I'm especially interested in being able to tell my colleagues "go to that jar and check that property" so I'm sure that my code will run on their server.

As alternative, I found a webpage Oracle GlassFish Server 3.1 Application Development Guide that says: "GlassFish Server supports the Java Servlet Specification version 3.0." but obviously for Glassfish 3.1, and I couldn't find one of those for every glassfish version (not even for mine -4.1 )

解决方案

Look at Java EE version. Servlet (and JSP, JSF, EJB, JPA, etc) version goes hand in hand with Java EE version.

  • Java EE 8 = Servlet 4.0
  • Java EE 7 = Servlet 3.1
  • Java EE 6 = Servlet 3.0
  • Java EE 5 = Servlet 2.5
  • J2EE 1.4 = Servlet 2.4
  • J2EE 1.3 = Servlet 2.3
  • J2EE 1.2 = Servlet 2.2

Look at the server homepage/documentation how it presents itself. For GlassFish, that is currently (with 4.1):

World's first Java EE 7 Application Server

So, it's Servlet 3.1.

But, with a big but, that's one thing. The second thing is, the webapp's web.xml version also plays a role. Not everyone knows that.

If your webapp's web.xml is declared conform Servlet 3.1 like below,

<?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>

then your webapp will also really run in Servlet 3.1 modus.

However, if it's declared conform Servlet 3.0 like below or even older,

<?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>

then your webapp will run in Servlet 3.0 compatibility modus, even when deployed to a Servlet 3.1 compatible container! The above influences the ServletContext#getMajorVersion() and getMinorVersion(), so they actually say nothing about the container, but only about the webapp itself.

If your webapp's web.xml contains a <!DOCTYPE>, regardless of the DTD and the version, then it will run in Servlet 2.3 compatibility modus, even when there's a newer XSD declared!

<?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>

这篇关于如何找到glassfish服务器的servlet API版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆