开发者

Preventing access to a jspx page from browser

I created a test.jspx file under WEB-INF and I am trying to access it via a servlet by a request dispatcher, but I am getting java.lang.RuntimeException: Cannot find FacesContext.

The web.xml mapping is as follows:

 <servlet-mapping>
    &开发者_如何学JAVAlt;servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
  </servlet-mapping>

It works fine if I use .jsp.

My request dispacther code is as follow:

RequestDispatcher dispatcher=getServletContext().getRequestDispatcher("/WEB-INF/test.jspx?sessid="+id);
dispatcher.forward( request, response );


The request URL (which you see in browser address bar) or the forward URL (which you used in RequestDispatcher#forward()) must match the URL pattern of the FacesServlet in order to get it to run and process all JSF components in the JSF page.

You've mapped the FacesServlet on an URL pattern of /faces/* and you're trying to invoke it from some homebrewed servlet (why?), so the forward URL must match that URL pattern. Put the page outside /WEB-INF and forward to /faces/test.jspx instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜