问题
I am using JBoss4.2 with the eclipse IDE. When I run the hellojsf
program using JSP view technology, it works fine. When I try with Facelets usings the same components, I am getting the below exception:
2012-06-20 12:41:30,941 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/HelloJSF].[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
java.lang.StackOverflowError
at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:216)
at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:545)
at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:216)
at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:545)
at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:216)
at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:545)
How is this caused and how can I solve it?
回答1:
The FacesServlet
has run in an infinite loop. That can happen if you're using old JSF 1.2 instead of newer JSF 2.x and didn't configure JSF properly to use XHTML instead of JSP. JSF 1.2 does not support Facelets while JSF 2.x has Facelets bundled.
If upgrading to JSF 2.0 is not an option (JBoss 4.2 as being a Servlet 2.5 compatible container should support it), then you need to install Facelets 1.x separately. Download jsf-facelets-1.1.15.jar and drop it in /WEB-INF/lib
and edit the web.xml
to tell JSF to use .xhtml
as default suffix.
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
The FacesServlet
mapping URL pattern must not be *.xhtml
, this would cause it to run in an infinite loop. Just keep it *.jsf
.
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
Further don't forget to configure the Facelets view handler in faces-config.xml
.
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>
Now you can open Facelets files the usual way by http://localhost:8080/context/page.jsf
like as you used for JSP files, with the only difference that you should have a page.xhtml
file instead of page.jsp
.
When using JSF 2.x, the context param and view handler are unnecessary as those are the default values for JSF 2.x already. Also when using JSF 2.x, the URL pattern can safely be set to *.xhtml
.
See also:
- Facelets 1.x developer documentation
- Migrating from JSF 1.2 to JSF 2.0
来源:https://stackoverflow.com/questions/11114723/using-facelets-instead-of-jsp-results-in-java-lang-stackoverflowerror-at-javax-s