为什么我的jsf标签不起作用? [英] why don't my jsf tags work?

查看:79
本文介绍了为什么我的jsf标签不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Eclipse JUNO中,我开始:

  1. 新的动态Web项目
  2. 名称:JSFTest;配置:JavaServer Faces v2.0项目
  3. JSF Capabilites:
  4. 将jar复制到WEB-INF/lib(jstl-api,jstl-impl,jsf-api,jsf-impl):

  5. 新的HTML到WebContent:带有"New Facelet合成页面"的index.xhtml,以及其中的代码:

  6. 在web.xml中,我将index.xhtml写入欢迎部分

  7. 当我在apache tomcat 7服务器上运行它时,结果(不必理会h1标题):

那么为什么不显示出文本和按钮呢?我怎么了我在youtube上看到了很多视频,我一直关注着他们,在视频中起作用了,但对我来说却是这样.

解决方案

因为您必须按照web.xml文件中的说明,访问/faces/虚拟文件夹下的index.xhtml页面进行FacesServlet url映射.

使JSF页面正常工作的一种简单方法是更改​​web.xml

中的url映射.

发件人:

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

收件人

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

如果您不想更改此设置,则必须将welcome-file更改为/faces/index.xhtml.

IMO最好是第一个选择,这样,FacesServlet将仅处理xhtml页,使用/faces/*将使其处理任何其他资源,如图像,CSS和JS文件.

In Eclipse JUNO, I started:

  1. new Dynamic Web Project
  2. Name: JSFTest; Configuration: JavaServer Faces v2.0 Project
  3. JSF Capabilites:
  4. Copy jars to WEB-INF/lib (jstl-api, jstl-impl, jsf-api, jsf-impl):

  5. new HTML to WebContent: index.xhtml with "New Facelet Composition Page", and the code inside:

  6. in web.xml, I write the index.xhtml into the welcome part

  7. when I run it on my apache tomcat 7 server, the result (don't bother about the h1 title):

So why doesn't it show the outtext and the button? What did I wrong? I saw a lot of video on youtube, I followed them, in the video it worked, but at me.

解决方案

Because you have to access to the index.xhtml page under /faces/ virtual folder as stated in your web.xml file for the FacesServlet url mapping.

A simple way to make your JSF page to work is to change the url mapping in your web.xml

From:

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

To

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

If you don't want to change this, you must change your welcome-file to /faces/index.xhtml.

IMO it will be better the first option, in this way the FacesServlet will only process the xhtml pages, using the /faces/* will make it process any other resource as images, CSS and JS files.

这篇关于为什么我的jsf标签不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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