Using Facelets instead of JSP results in java.lang.StackOverflowError at javax.servlet.http.HttpServletRequestWrapper.getSession()

邮差的信 提交于 2019-12-24 02:43:19

问题


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

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