Tomcat 6 JSF/JSP 文件名配置问题

发布于 2024-08-24 04:16:56 字数 3075 浏览 4 评论 0 原文

我有一个 JSF 应用程序通过 Tomcat 6 从 Eclipse Ganymede 部署。后者建议使用 JSP 2.0。我正在使用 Sun RI JSF 实现和 RichFaces 3.3.2SR1。

我的 index.jsp 文件根据浏览器的请求导致控制台出现此错误:

05-Mar-2010 12:04:41 org.apache.catalina.core.ApplicationDispatcher invoke 严重:servlet jsp 的 Servlet.service() 抛出异常 org.apache.jasper.JasperException: 模板文本中不允许使用 /index.jsp(35,41) #{..} ...

好吧,我已经看到了有关此主题的各种其他帖子,包括各种 jars/taglibs/syntaxes 等版本的不兼容性等。

使用 http://localhost:8989/myapp/index 调用 index.jsp .jsf (或 .jsp - 给出相同的错误),并且包含

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich">

应该没问题,因为 Facelets 位于我正在使用的 Mojarra 2.0.2FCS 中。我似乎必须使用上面的语法而不是例如。 <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> 作为 Facelets URI 导致 Eclipse 提示 Cannot find “http://java.sun.com/jsf/facelets”的标记库描述符。

我的问题与我列出这些标签的方式有关吗?

我的 Ant 构建文件引用了这些 Tomcat jar:

    <fileset dir="${cliTomcatlib}">
        <include name="servlet-api.jar" />
        <include name="jsp-api.jar" />
    </fileset>

所以我很困惑如何解决这个错误。感觉这将是一个简单的修复,但由于我使用的是应该与 JSP 2.0 兼容的最新 jar,我想知道为什么会出现此错误。 JSF

编辑 为了响应 BalusC 的智慧,我更正了两个对外部 jsp 文件的引用,并将所有 .jsp 重命名为 .xhtml。我记得还更新了我的 faces-config.xml

当像这样请求 index.xhtml 时,重新部署现在会出现一个大且重复的错误:

05-Mar-2010 13:29:26 org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet Faces Servlet threw exception
java.lang.StackOverflowError
    at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:824)
    at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:216)
    at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:544)
...
    at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:216)
    at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:544)
    at com.sun.faces.context.ExternalContextImpl.getSession(ExternalContextImpl.java:151)
    at javax.faces.application.ViewHandler.calculateCharacterEncoding(ViewHandler.java:242)
    at javax.faces.application.ViewHandler.initView(ViewHandler.java:458)
    at com.sun.faces.application.view.MultiViewHandler.initView(MultiViewHandler.java:106)
    at org.ajax4jsf.application.ViewHandlerWrapper.initView(ViewHandlerWrapper.java:128)
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:109)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)

我承认这不是很有启发性,除了堆栈跟踪的前几行重复了很多次之外不得不更改 Eclipse 上的控制台缓冲区。如果有人以前看过这个,我会非常感激。

标记

I've a JSF app deploying from Eclipse Ganymede through Tomcat 6. The latter suggests JSP 2.0. I'm using Sun RI JSF implementation and RichFaces 3.3.2SR1.

My index.jsp file on request from the browser causes this error to the console:

05-Mar-2010 12:04:41 org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: /index.jsp(35,41) #{..} is not allowed in template text

...

OK, I've seen various other posts on this subject including incompatibilities of versions of the various jars/taglibs/syntaxes etc.

The index.jsp is called using http://localhost:8989/myapp/index.jsf (or .jsp - gives the same error), and contains

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich">

which should be alright as facelets is in Mojarra 2.0.2FCS which I'm using. I seem to have to use the above syntax rather than eg. <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> as the facelets URI causes Eclipse to say Cannot find the tag library descriptor for "http://java.sun.com/jsf/facelets".

Is my problem to do with the way I'm listing these tags?

My Ant build file refers to these Tomcat jars:

    <fileset dir="${cliTomcatlib}">
        <include name="servlet-api.jar" />
        <include name="jsp-api.jar" />
    </fileset>

so I'm stumped as to how I can get round this error. It feels like it would be a simple fix but as I'm using latest jars that should be compatible with JSP 2.0, I'm wondering why I'm getting this error. JSF

EDIT
In response to BalusC's wisdom, I corrected two references to external jsp files and renamed all .jsp to .xhtml. I remembered to also update my faces-config.xml.

Redeploying now errors with a large and repeating error when the index.xhtml is requested like this:

05-Mar-2010 13:29:26 org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet Faces Servlet threw exception
java.lang.StackOverflowError
    at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:824)
    at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:216)
    at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:544)
...
    at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:216)
    at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:544)
    at com.sun.faces.context.ExternalContextImpl.getSession(ExternalContextImpl.java:151)
    at javax.faces.application.ViewHandler.calculateCharacterEncoding(ViewHandler.java:242)
    at javax.faces.application.ViewHandler.initView(ViewHandler.java:458)
    at com.sun.faces.application.view.MultiViewHandler.initView(MultiViewHandler.java:106)
    at org.ajax4jsf.application.ViewHandlerWrapper.initView(ViewHandlerWrapper.java:128)
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:109)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)

which I admit isn't very illuminatory other than the first few lines of the stack trace are repeated so many times I had to change the console buffer on Eclipse. I'd be overflowing with gratitude if anyone has seen this before.

Mark

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ζ澈沫 2024-08-31 04:16:56
org.apache.jasper.JasperException: 模板文本中不允许使用 /index.jsp(35,41) #{..} 

JSP 中的模板文本中确实不允许统一 EL。仅允许在 Facelets 中使用。

使用 http://localhost:8989/myapp/index.jsf (或 .jsp - 给出相同的错误)并包含


您将 JSP 与 Facelets 混淆。你可以而且不应该那样做。这是两种不同的视图技术。使用其中之一或其他。 JSP 用于 <%@taglib %> 内容,Facelets 是面向 XHTML 的 东西。对于 JSF 2.0,您应该使用 Facelets。将所有文件从 *.jsp 重命名为 *.xhtml 并替换并删除任何 <% %>< ;jsp:xxx> 的东西。

要了解有关 Facelets 的更多信息,请从 Java EE 6 教程部分开始第二章 5。如果您想回退到古老的 JSP 而不是 JSF 2.0 的 Facelets,那么您需要在 JSF 中重新配置视图处理程序。

除了这个问题之外,顺便说一句,Tomcat 6.0 是 JSP 2.1,而不是 JSP 2.0。

更新:getSession() 上的 StackOverflowError 表示 servlet/filter 映射中存在无限递归。您的 FacesServlet 是如何映射的?它应该映射为侦听 *.jsfurl-pattern,而不是 *.xhtml。否则它将递归地调用自身。请查阅/参考 JSF 2.0 书籍/教程/文档 密切关注如何正确配置它。

org.apache.jasper.JasperException: /index.jsp(35,41) #{..} is not allowed in template text 

Unified EL is indeed not allowed in template text in JSP. It's only allowed in Facelets.

The index.jsp is called using http://localhost:8989/myapp/index.jsf (or .jsp - gives the same error) and contains

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
     xmlns:ui="http://java.sun.com/jsf/facelets"

You're mixing up JSP with Facelets. You can and should not to that. Those are two distinct view technologies. Use the one or other. JSP is for the <%@taglib %> stuff and Facelets is XHTML oriented with <html xmlns> and <ui:xxx> stuff. For JSF 2.0 you're supposed to use Facelets. Rename all files from *.jsp to *.xhtml and replace and get rid of any <% %> and <jsp:xxx> stuff.

To learn more about Facelets, start here in the Java EE 6 tutorial part II chapter 5. If you'd like to fall back to the ancient JSP instead of Facelets for JSF 2.0, then you'll need to reconfigure the view handler in JSF.

Apart from the problem, Tomcat 6.0 is by the way JSP 2.1, not JSP 2.0.

Update: the StackOverflowError on getSession() indicates an infinite recursion in the servlet/filter mappings. How is your FacesServlet mapped? It should be mapped to listen on an url-pattern of *.jsf, not *.xhtml. Otherwise it will call itself recursively. Please consult/refer the JSF 2.0 books/tutorials/documentation closely how to configure it properly.

花想c 2024-08-31 04:16:56

将 JSF impl jar 添加到 Tomcat 的 lib 或您的应用程序 lib 中,然后重试。
有关更多信息,请参阅

Add JSF impl jars to Tomcat's lib or your app lib and try again.
See this for more.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文