Get rid of ;jsessionid=xxx path parameter in URL when using h:button
Asked Answered
C

1

5

I'm using OmniFaces FullAjaxExceptionHandler in Tomcat7 and JSF 2.1 to handle the ViewExpiredException. I've setup the same error pages as OmniFaces showcase. Look here for error pages and here for template.

It works fine. When the session is expired, then I end up in expired.xhtml error page. However, when I click the below link in the error page,

 <p><a href="#{requestScope['javax.servlet.error.request_uri']}">Back to initial page.</a></p>

then I get the following exception:

com.sun.faces.mgbean.ManagedBeanCreationException: An error occurred performing resource injection on managed bean 

This is not a big problem. I need a button that points the user to the home page anyway. So I replaced it by the below button:

<h:button value="Home" outcome="logout" />

along with this navigation case:

<navigation-rule>
    <from-view-id>*</from-view-id>
    <navigation-case>
        <from-outcome>logout</from-outcome>
        <to-view-id>/stdPortal/index.xhtml</to-view-id>
        <redirect/>
    </navigation-case>
</navigation-rule>

The navigation took me to the correct page, however the session ID appears in the URL:

https://localhost/stdPortal/index.xhtml;jsessionid=B68784B4ED8882A6575A2EE4012AF1B5

I don't want this. How do I get rid of it? I want the URL to be like:

https://localhost/stdPortal/index.xhtml
Chorister answered 27/6, 2013 at 15:9 Comment(0)
W
11

You can get rid of jsessionid path fragment in URL by adding the following to web.xml:

<session-config>
    <tracking-mode>COOKIE</tracking-mode>
</session-config>

It basically disables URL-rewriting.

Wrote answered 27/6, 2013 at 17:35 Comment(2)
@ BalusC as usual a Genius. You always understand the problem and provide the perfect solution. Not knowing that they must seek "jsessionid path fragment" I could not find the solution. why jsession is stored in url is a TomcatBug or are some tech problemChorister
The jsessionid path fragment will be appended to URLs if the new session has been established while the response is already committed. Increasing the response buffer size to the same size as your largest page should also help.Wrote

© 2022 - 2024 — McMap. All rights reserved.