JSF和库不清楚 [英] JSF and Libraries Unclarity

查看:119
本文介绍了JSF和库不清楚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我在尝试学习一些关于JSF的东西,经过一段时间花在servlet和JSP上。我学到了基础知识,做了几个简单的例子,有一个基本的工作流,但我仍然不明白什么是javax.faces.webapp.FacesServlet的东西。

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

我知道Faces Servlet它只是一个内部名称,仅用于XML,在一个类中绑定,在这种情况下:javax.faces.webapp.FacesServlet。但是这个班呢在哪里呢?我正在使用Eclipse,创建一个新的动态项目,GlassFish 4.0作为服务器,JSF 2.0作为配置(选择没有库),也没有导入任何jar。怎么可以工作?当我尝试使用JBoss运行相同的东西时,我必须导入javax.faces-2.2.2.jar文件。



好的,该图书馆可能已经包含在GlassFish中,因为它可以工作,但如果我尝试在另一个服务器上部署我的应用程序,我会面临任何问题吗?像JBoss或Websphere一样。



简而言之:使用JSF技术的前提是什么?)



谢谢。

解决方案

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

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

现在,我们可以使用 Faces Servlet在web.xml文件中引用此类名称。接下来要做的是定义该servlet将处理的URL。这是在这个配置中完成的:

 < servlet-mapping> 
< servlet-name> Faces Servlet< / servlet-name>
< url-pattern> *。jsf< / url-pattern>
< / servlet-mapping>因此,以 jsf


>后缀将由Faces Servlet处理。您可以使用其他URL模式进行servlet映射。这在这里有更好的解释: JSF Facelets:有时我看到URL是.jsf,有时是.xhtml。为什么?


如果我尝试在另一台服务器上部署我的应用程序,我会面临任何问题吗?像JBoss或Websphere?


如果应用程序服务器是符合Java EE 5的服务器,那么您将可以使用这个servlet Mojarra以JSF 1.2的形式实现。对于符合Java EE 6标准的服务器,这将是针对JSF 2.x的Mojarra实现(检查应用程序服务器的注释以了解确切的版本)。目前,使用GlassFish 4,您将获得Mojarra for JSF 2.2。



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


使用JSF技术时,先决条件是什么?


这在 StackOverflow JSF wiki 中有所介绍。从那里获取:


最低要求




  • JSF 1.0和1.1需要最少的Servlet 2.4 / JSP 2.0和Java 1.4。

  • JSF 1.2适用于Servlet 2.4,但需要最少的JSP / EL 2.1,与Servlet 2.5,所以毕竟需要Servlet 2.5。如果将Facelets 1.x中的JSP 2.1替换为默认视图技术,那么可以在Servlet 2.4上使用JSF 1.2。它需要最少的Java 1.5。

  • 默认情况下使用的JSF 2.0 Facelets 2.x需要最少的EL 2.1,它与Servlet 2.5并行,所以需要所有的Servlet 2.5。如果您提供自己的EL 2.1 API / impl,那么您可以在理论上在Servlet 2.4上运行JSF 2.0。它需要最少的Java 1.5。

  • JSF 2.1使用一些Servlet 3.0的特定功能,但向后兼容Servlet 2.5。这些Servlet 3.0功能是可选的。

  • JSF 2.2需要最少的Servlet 3.0,因为新的文件上传组件在内部使用标准的Servlet 3.0 API,而不需要第三方库。它需要最少的Java 1.6。



Servlet 2.4容器的示例是Tomcat 5.5.x,JBoss AS 4.x和Sun Java应用服务器。



Servlet 2.5容器的示例是Tomcat 6.0.x,JBoss AS 5.x和GlassFish 2.x。



Servlet 3.0容器的示例是Tomcat 7.0.x,JBoss AS 6.x和7.x和GlassFish 3.x。



Servlet 3.1示例容器是Tomcat 8.0.x,WildFly 8.x和GlassFish 4.x。



After some time spent with servlets and JSPs now i'm trying to learn something about JSF. I've learned the basics, made a couple of simple examples, have a basic ideea of the 'workflow' but I still can't understand what's with the javax.faces.webapp.FacesServlet thing.

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

I know that "Faces Servlet" it's just an 'internal' name just for the XML and that it gets bind with a class, in this case: javax.faces.webapp.FacesServlet. But where is this class anyway?! I'm using Eclipse, created a new Dynamic Project, GlassFish 4.0 as Server, JSF 2.0 as Configuration (selected no library) and neither did I import any jar. How can it be working? And when I try to run the same thing with JBoss I must import a javax.faces-2.2.2.jar file.

Ok, the library might be already included in GlassFish since it works but... will I face any problems if I try to deploy my app on another server? Like JBoss or Websphere.

In a nutshell: what are the prerequisites when working with JSF technology :)

Thank you.

解决方案

javax.faces.webapp.FacesServlet is a class that implements Servlet interface. In order to be recognized in your application, you should add it in the web.xml as a <servlet>. This is basically done in this configuration:

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

Now, we can refer to this class in the web.xml file using the Faces Servlet name. Next thing do to is define the URL that will be handled by this servlet. This is done in this configuration:

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

So, any GET or POST request to this application server that ends with jsf suffix will be handled by Faces Servlet. You can use other URL patterns for the servlet mapping. This is better explained here: 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?

If the application server is a Java EE 5 compliant server, then you will have access to this servlet by using Mojarra implementation in form of JSF 1.2. For Java EE 6 compliant servers this will be in Mojarra implementation in for of JSF 2.x (check the notes of the application server to know the exact version). Currently, with GlassFish 4, you get Mojarra for JSF 2.2.

In case the application server is not a Java EE compliant server e.g. Tomcat, you must add the libraries manually in WEB-INF/lib folder of your web application. Which libraries to add? Depending on the JSF version and its requirements (read further).

what are the prerequisites when working with JSF technology?

This is covered in StackOverflow JSF wiki. Taken from there:

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.

这篇关于JSF和库不清楚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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