why don't my jsf tags work? [duplicate]

▼魔方 西西 提交于 2019-12-11 15:11:46

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/15046821/why-dont-my-jsf-tags-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!