JSF页面未呈现为HTML [英] JSF page not rendering as HTML

查看:64
本文介绍了JSF页面未呈现为HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行一个非常基本的JSF页面.使用Websphere 7.0作为服务器,因此我试图坚持使用JSF 1.2.浏览器未呈现html,这意味着它只是显示所有html代码,包括doctype等.
我的第一个猜测可能是它没有通过FacesServlet传递,但是当url-pattern不匹配时,它找不到页面.它是JSF版本问题吗?还有其他想法吗?谢谢大家

I'm trying to get a very basic JSF page running. Using Websphere 7.0 as the server so I'm trying to stick with JSF 1.2. The browser isn't rendering the html, by which I mean that it's simply displaying all the html code including doctype, etc.
My first guess might be that it's not getting passed through the FacesServlet, but when the url-pattern doesn't match it gets page not found. Is it a JSF version issue? Any other ideas? Thanks folks

我在我的lib文件夹中包含了jstl-api-1.2.jar和jstl-imp-1.2.jar.

I've included jstl-api-1.2.jar and jstl-imp-1.2.jar in my lib folder.

我设置了以下web.xml:

I have the following web.xml set up:

<?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">
  <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.application.CONFIG_FILES</param-name>
        <param-value>/WEB-INF/faces-config.xml</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>
</web-app>

faces-config.xml:

faces-config.xml:

<?xml version="1.0"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
      http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
   version="1.2">
</faces-config>

index.jsp:

index.jsp:

<% response.sendRedirect("page-a.jsf"); %>

以及xhtml文件的开头:

And the start of the xhtml file:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html">

推荐答案

您似乎正在尝试将JSF 1.2与Facelets 1.x结合使用.很好,但是 faces-config.xml 中缺少Facelets视图处理程序.您应该在其中输入以下内容:

You seem to be trying to use JSF 1.2 with Facelets 1.x. That's fine, but the Facelets view handler is missing in faces-config.xml. You should have the following entry in there:

<application>
    <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>    
</application>

请注意,您需要 <代码> jsf-facelets.jar 文件.

Note that you need the jsf-facelets.jar file for this.

还请注意,您实际上不需要与Web应用程序一起提供 JSTL ;作为成熟的Java EE 5应用程序服务器,WebSphere 7已经提供了它自己.我建议删除那些JSTL JAR文件,因为它可能与WebSphere提供的文件冲突.WebSphere也已经提供了JSF,但是自Java EE 6以来,Facelets并不是Java EE的一部分.

Also note that you actually don't need to provide JSTL along with your webapp; WebSphere 7 as being a full fledged Java EE 5 application server already provides it by itself. I recommend to remove those JSTL JAR files as it might possibly conflict with the ones provided by WebSphere. JSF is also already provided by WebSphere, but Facelets not as that is only part of Java EE since Java EE 6.

鉴于缺少Facelets视图处理程序,我想知道您是否正在阅读正确的Facelets教程(由于JSF 2.0,Facelets < view-handler> 配置不是强制性的,因为它是默认配置视图处理程序已经存在,所以也许您不小心阅读了针对JSF 2.0的教程,而您实际上应该阅读的是针对JSF 1.x的教程,所以为了完整起见,这是指向

Given the lack of Facelets view handler, I wonder if you're reading the right Facelets tutorial (since JSF 2.0, a Facelets <view-handler> configuration is not mandatory as it's the default view handler already, so perhaps you were accidently reading a JSF 2.0 targeted tutorial, while you should really be reading the one for JSF 1.x), so for the sake of completeness, here's a link to the official developer guide of Facelets 1.x.

这篇关于JSF页面未呈现为HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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