JSF navigation redirect to previous page

前端 未结 7 1490
一向
一向 2020-12-09 07:06

Once the user successful login to the system, the system will redirect the user to the homepage. Now my problem is, if the user clicks on the view account page without login

相关标签:
7条回答
  • 2020-12-09 07:08

    Not sure, but try doing this through ExternalContext facilities:

    Something like this:

    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
    externalContext.redirect(externalContext.encodeResourceURL(externalContext.getRequestContextPath()+getUrl()));
    
    0 讨论(0)
  • 2020-12-09 07:15

    Logic described (login-redirect) should be implemented through Filter mechanics. Also you can try standard jsf navigation rules(if it can fit you case). And if you still want to send redirect to a custom url and don't want to use Filters, do it in your servlet in render phase, not in your jsf bean.

    0 讨论(0)
  • 2020-12-09 07:18

    This exception is caused because you called response.sendRedirect() and didn't block JSF from rendering the normal response. You need to inform JSF that it doesn't need to handle normal response by adding

    FacesContext.getCurrentInstance().responseComplete(); 
    

    to the action method.

    Or, even better, just don't get the HttpServletResponse from under the JSF's hoods, but instead do:

    FacesContext.getCurrentInstance().getExternalContext().redirect(url);
    

    This will automatically invoke responseComplete() and it also keeps your code clean from unnecessary Servlet API stuff. Also see the ExternalContext API.

    0 讨论(0)
  • 2020-12-09 07:20

    Placing the below syntax in web.xml should work:

    <context-param>
    <param-name>com.sun.faces.writeStateAtFormEnd</param-name>
    <param-value>false</param-value>
    </context-param>
    
    0 讨论(0)
  • 2020-12-09 07:26

    java.lang.IllegalStateException: Cannot forward after response has been committed

    The exception is fairly clear:

    • The response has been committed.
    • You cannot forward after the response has been committed.

    What doesn't make sense?

    0 讨论(0)
  • 2020-12-09 07:32

    You're too late and that is giving you the exception. Do it in a phaselistener before the render response phase.

    0 讨论(0)
提交回复
热议问题