jsf2 xhtml页面无法被浏览器解释 [英] jsf2 xhtml pages not interpreted by browser

查看:80
本文介绍了jsf2 xhtml页面无法被浏览器解释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试coreservlets网站上的应用程序"jsf-blank",以了解jsf的工作原理,但我的浏览器未显示xhtml页面的内容.

I am testing the application "jsf-blank" from coreservlets site in order to understand how jsf works but my browser doesn't show the content of the xhtml page.

我使用Tomcat 6和Eclipse Indigo.

I use Tomcat 6 and Eclipse Indigo.

您知道为什么浏览器中的页面空白吗?

Have you any idea why the page is blank in my browser ?

谢谢您的帮助.

谢谢,但这不适用于jsp指令,这是我的web.xml的内容:

Thank you but it doesn't work with jsp directive and this is the content of my web.xml :

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>
<context-param>
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.xhtml</param-value>
</context-param>
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>

最新更新:

我尝试了您的解决方案,但是我遇到了同样的问题,jsf标记不是由浏览器呈现的(我是JSF的新手).

I tried your solutions but I have the same problem, jsf tags aren't rendered by browser (I am a newbie in JSF).

我的测试非常简单:

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"                             xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
    <welcome-file>index.xhtml</welcome-file>
</welcome-file-list>

index.xhtml:

index.xhtml :

  <!DOCTYPE html>
  <html lang="en"
     xmlns="http://www.w3.org/1999/xhtml"
     xmlns:f="http://java.sun.com/jsf/core"
     xmlns:h="http://java.sun.com/jsf/html"
     xmlns:ui="http://java.sun.com/jsf/facelets">
     <h:head>
       <title><h:outputText value="First JSF Application" /></title>
     </h:head>
     <h:body>
        <h:outputText value="Test" /> 
     </h:body>
   </html>

上下文名称:jsf-blank

Context name : jsf-blank

我使用url测试: http://localhost:8080/jsf-blank/index.xhtml

结果:空白页

最新更新:

谢谢,我的问题已经解决,我认为问题的根源是tomcat文件夹shared/lib中的面孔丰富的3.3罐子.

Thank you, my problem is solved, I think the origin of problem was rich-faces 3.3 jars in my tomcat's folder shared/lib.

我移开了这些罐子,现在可以用了,你知道为什么会出问题吗?

I removed these jars and now it's working, do you know why it's a problem ?

推荐答案

当您发送请求的URL与FacesServlet的URL模式不匹配的请求时,可能会发生这种情况,从而导致JSF无法正常工作运行.根据servlet映射的URL模式,您必须请求扩展名为.jsf的XHTML页面.假设您有一个index.xhtml,那么您需要通过 http://localhost:8080/contextname/index来调用它.jsf .

That can happen when you have sent a request whose URL does not match the URL pattern of the FacesServlet which in turn causes that the JSF works won't run at all. According to the URL pattern of your servlet mapping, you have to request your XHTML page with .jsf extension. Imagine that you've an index.xhtml, then you'd need to invoke it by http://localhost:8080/contextname/index.jsf.

但是,我建议仅将*.jsf URL模式替换为*.xhtml,这样您就不必担心后缀.如下更改您的web.xml:

I however recommend to just replace the *.jsf URL pattern by *.xhtml so that you never need to worry about and fiddle with suffixes. Change your web.xml as follows:

<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

<welcome-file-list>
    <welcome-file>index.xhtml</welcome-file>
</welcome-file-list>

并通过 http://localhost:8080/contextname/index.xhtml 打开页面.

这篇关于jsf2 xhtml页面无法被浏览器解释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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