Search code examples
javasessiontomcatvirtualhostmod-proxy

How to configure apache-vhost.conf file for getting Session value from Java


Existing Config File setting for VirtualHost in Tomcat Server:

`<VirtualHost *:96>
  ServerName example.in
  ServerAlias www.example.in
  ProxyPass / http://127.0.0.1:8080/example/
  ProxyPassReverse / http://127.0.0.1:8080/example/

  <IfModule mod_jk.c>
  JkMount /*.jsp ajp13
  JkMount /*.do ajp13
  JkMount /*.* ajp13
  JkMount /servlet/* ajp13
  JkMount /servlets/* ajp13
</IfModule>
</VirtualHost>`

By using this configuration I am not able to get the Session Value, which is being set in Java file request.getSession().setAttribute("ActiveSession", output.getParameters().get("userDetailsList"));

I am trying to retrieve the value in jsp by standard jsp code as <%session.getAttribute("ActiveSession")%>

Problem: when I am using website link 'example.in' I'm not getting the session value in JSP.

But using http://127.0.0.1:8080/example/ I am getting the value.

Already Tried :

`<VirtualHost *:96>
  ServerName example.in
  ServerAlias www.example.in
  ProxyPass / http://127.0.0.1:8080/example/
  ProxyPassReverse / http://127.0.0.1:8080/example/
  Session On
  SessionEnv On
  SessionCookieName session path=/
  SessionHeader X-Replace-Session
  <IfModule mod_jk.c>
  JkMount /*.jsp ajp13
  JkMount /*.do ajp13
  JkMount /*.* ajp13
  JkMount /servlet/* ajp13
  JkMount /servlets/* ajp13
</IfModule>

`

Help will be appreciated as I have already wasted 5 good hrs on this.


Solution

  • If someone is still struggling to get this, here is the working configuration:

    <VirtualHost *:96>
     ServerName example.in
     ServerAlias www.example.in
     ProxyPass / http://127.0.0.1:8080/example/
     ProxyPassReverse / http://127.0.0.1:8080/example/
     ProxyPassReverseCookiePath / http://127.0.0.1:8080/example/
     <IfModule mod_jk.c>
      JkMount /*.jsp ajp13
      JkMount /*.do ajp13
      JkMount /*.* ajp13
      JkMount /servlet/* ajp13
      JkMount /servlets/* ajp13
     </IfModule>
    </VirtualHost>