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 楼答案
javax.faces.webapp.FacesServlet
是一个实现Servlet
接口的类。为了在应用程序中被识别,您应该将其添加到web中。xml作为<servlet>
格式。这基本上是在此配置中完成的:现在,我们可以在web上参考这个类。使用facesservlet名称的xml文件。接下来要做的是定义将由这个servlet处理的URL。这是在以下配置中完成的:
因此,任何以jsf后缀结尾的对该应用服务器的GET或POST请求都将由facesservlet处理。您可以使用其他URL模式进行servlet映射。这在这里得到了更好的解释:JSF Facelets: Sometimes I see the URL is .jsf and sometimes .xhtml. Why?
如果应用服务器是兼容JavaEE5的服务器,那么您可以通过使用JSF1.2形式的Mojara实现来访问这个servlet。对于兼容JavaEE6的服务器,这将在JSF2的Mojarra实现中实现。x(检查应用程序服务器的注释以了解确切版本)。目前,在GlassFish4中,您可以获得用于JSF2.2的Mojara
如果应用服务器不是兼容Java EE的服务器,例如Tomcat,则必须在WEB应用程序的WEB-INF/lib文件夹中手动添加库。要添加哪些库?取决于JSF版本及其要求(请进一步阅读)
这将在StackOverflow JSF wiki中介绍。从此处开始: