奇怪的jsf重定向行为

时间:2010-10-02 23:12:43

标签: jsf navigation redirect

我尝试通过指定导航规则导航到另一个带有重定向的页面。 我尝试重定向的网页在直接调用时效果很好。

当我将edirection设置为一个jsp页面时,其中只包含一个<jsp:forward page="faces/another.xhtml" />消息,我在nullpointerexception之后得到了这个,并且重定向失败:

java.lang.NullPointerException
    at org.icefaces.util.EnvUtils.isICEfacesView(EnvUtils.java:69)
    at org.icefaces.event.BridgeSetup.processEvent(BridgeSetup.java:66)
    at javax.faces.event.SystemEvent.processListener(SystemEvent.java:102)
    at com.sun.faces.application.ApplicationImpl.processListeners(ApplicationImpl.java:1993)
    at com.sun.faces.application.ApplicationImpl.invokeListenersFor(ApplicationImpl.java:1969)
    at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:299)
    at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:243)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:114)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
    at java.lang.Thread.run(Unknown Source)
03.Eki.2010 02:07:58 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NullPointerException
    at javax.faces.component.UIViewRoot.getViewMap(UIViewRoot.java:1523)
    at javax.faces.component.UIViewRoot.getViewMap(UIViewRoot.java:1487)
    at org.icefaces.util.EnvUtils.isICEfacesView(EnvUtils.java:70)
    at org.icefaces.context.DOMPartialViewContext.getPartialResponseWriter(DOMPartialViewContext.java:97)
    at org.icefaces.context.DOMPartialViewContext.getPartialResponseWriter(DOMPartialViewContext.java:95)
    at com.sun.faces.context.AjaxExceptionHandlerImpl.handlePartialResponseError(AjaxExceptionHandlerImpl.java:190)
    at com.sun.faces.context.AjaxExceptionHandlerImpl.handle(AjaxExceptionHandlerImpl.java:119)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
    at java.lang.Thread.run(Unknown Source)

然后我将导航规则直接设置为/faces/another.xhtml。重定向成功,但我收到以下警告消息:

WARNING: JSF1015: Request path '/faces/another.xhtml' begins with one or more
occurrences of the FacesServlet prefix path mapping '/faces'.

您认为设置导航的正确方法是什么? 非常感谢你。

1 个答案:

答案 0 :(得分:3)

显然你已经在JSF环境中了。从网址中删除/faces前缀。

<jsp:forward page="another.xhtml" />

请注意,您不是在此处重定向,而是将请求转发到其他来源。重定向基本上指示客户端向服务器发出全新的HTTP请求,该服务器的URL随后会反映在浏览器地址栏中。重定向通常由bean的操作方法中的ExternalContext#redirect()完成(在调用HttpServletResponse#sendRedirect()然后FacesContext#responseComplete()的情况下,或者通过向{{3}}添加<redirect/>条目。 <navigation-case>中的faces-config.xml