有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

javajsf与库不一致性

在花了一段时间使用servlet和JSP之后,我现在正试图学习一些关于JSF的知识。我已经学习了基础知识,做了几个简单的例子,对“工作流”有了一个基本的概念,但我仍然不明白javax是怎么回事。面孔。网络应用。脸小东西

<servlet>
  <servlet-name>Faces Servlet</servlet-name>
  <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
  </servlet>
<servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.jsf</url-pattern>
  </servlet-mapping>

我知道“FacesServlet”只是XML的一个“内部”名称,它与一个类绑定,在本例中是javax。面孔。网络应用。FacesServlet。但这门课到底在哪里?!我使用Eclipse创建了一个新的动态项目,GlassFish4.0作为服务器,JSF2.0作为配置(没有选择任何库),我也没有导入任何jar。它是怎么工作的?当我试图用JBoss运行同样的东西时,我必须导入一个javax。面-2.2.2。jar文件

好的,库可能已经包含在GlassFish中,因为它可以工作,但是。。。如果我尝试在另一台服务器上部署我的应用程序,我会遇到任何问题吗?比如JBoss或Websphere

简而言之:使用JSF技术的先决条件是什么:)

多谢各位


共 (1) 个答案

  1. # 1 楼答案

    javax.faces.webapp.FacesServlet是一个实现Servlet接口的类。为了在应用程序中被识别,您应该将其添加到web中。xml作为<servlet>格式。这基本上是在此配置中完成的:

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    

    现在,我们可以在web上参考这个类。使用facesservlet名称的xml文件。接下来要做的是定义将由这个servlet处理的URL。这是在以下配置中完成的:

    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    

    因此,任何以jsf后缀结尾的对该应用服务器的GET或POST请求都将由facesservlet处理。您可以使用其他URL模式进行servlet映射。这在这里得到了更好的解释:JSF Facelets: Sometimes I see the URL is .jsf and sometimes .xhtml. Why?

    will I face any problems if I try to deploy my app on another server? Like JBoss or Websphere?

    如果应用服务器是兼容JavaEE5的服务器,那么您可以通过使用JSF1.2形式的Mojara实现来访问这个servlet。对于兼容JavaEE6的服务器,这将在JSF2的Mojarra实现中实现。x(检查应用程序服务器的注释以了解确切版本)。目前,在GlassFish4中,您可以获得用于JSF2.2的Mojara

    如果应用服务器不是兼容Java EE的服务器,例如Tomcat,则必须在WEB应用程序的WEB-INF/lib文件夹中手动添加库。要添加哪些库?取决于JSF版本及其要求(请进一步阅读)

    what are the prerequisites when working with JSF technology?

    这将在StackOverflow JSF wiki中介绍。从此处开始:

    Minimum requirements

    • JSF 1.0 and 1.1 requires a minimum of Servlet 2.4 / JSP 2.0 and Java 1.4.
    • JSF 1.2 works on Servlet 2.4, but requires a minimum of JSP/EL 2.1 which goes hand in hand with Servlet 2.5, so it after all requires Servlet 2.5. If you replace JSP 2.1 by Facelets 1.x as default view technology, then you can use JSF 1.2 on Servlet 2.4. It requires a minimum of Java 1.5.
    • JSF 2.0 which uses by default Facelets 2.x requires a minimum of EL 2.1 which goes hand in hand with Servlet 2.5, so it requires after all Servlet 2.5. If you supply your own EL 2.1 API/impl, then you can in theory run JSF 2.0 on Servlet 2.4. It requires a minimum of Java 1.5.
    • JSF 2.1 uses some Servlet 3.0 specific features, but is backwards compatible with Servlet 2.5. Those Servlet 3.0 features are optional.
    • JSF 2.2 requires a minimum of Servlet 3.0, because of the new file upload component which is internally using the standard Servlet 3.0 API without the need for 3rd party libraries. It requires a minimum of Java 1.6.

    Examples of Servlet 2.4 containers are Tomcat 5.5.x, JBoss AS 4.x and Sun Java Application Server.

    Examples of Servlet 2.5 containers are Tomcat 6.0.x, JBoss AS 5.x and GlassFish 2.x.

    Examples of Servlet 3.0 containers are Tomcat 7.0.x, JBoss AS 6.x and 7.x and GlassFish 3.x.

    Examples of Servlet 3.1 containers are Tomcat 8.0.x, WildFly 8.x, and GlassFish 4.x.