问题
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
I've included jstl-api-1.2.jar and jstl-imp-1.2.jar in my lib folder.
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:
<?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:
<% response.sendRedirect("page-a.jsf"); %>
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">
回答1:
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>
Note that you need the jsf-facelets.jar file for this.
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.
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.
来源:https://stackoverflow.com/questions/13980040/jsf-page-not-rendering-as-html