Expand my Community achievements bar.

Session handling across the nodes and web server

Avatar

Level 3

Hi experts, 

 

I am working in an AEM app which does following -

 

  1. User submits the data through AEM forms
  2. We collect the data in AEM form action jsp and make a string 
  3. We store string in a session (HTTP session i.e. session.setAttribute )
  4. AEM redirects user to a thank you page
  5. We have a “Call to action” on thank you page
  6. On this call to action, we hit a backend JSP say”createfile.jsp” that reads the string from session variable and create a text file to download (session.getAttribute)

 

This works in single nodes (like author, publish etc), but when I am dealing with the web server it doesn’t. I am not able to collect the session data.  I have 2 author, 2 pub nodes and 1 web server.

 

Here is the form action script

submiForm.jsp

<%

String str=request.getParameter("bnfname4");

request.getSession().setAttribute("data", str);

%>

 

 

Here is the createfile.jsp

<%

String txt=(String)request.getSession().getAttribute("data");

 

%>

 

Any idea??

5 Replies

Avatar

Level 10

Have you set up sticky connections ??

If you are managing sessions between 2 pub instance with 1 web server, you need to configure the sticky connection in the dispatcher

Avatar

Level 7

You definitely have to use sticky connection to address this issue, as Loki said. I guess from AEM 6.2 we dont have to use sticky session anymore with these kind of scenarios. Am I correct @bsloki.

Avatar

Level 5

Hello Tuhin,

Using server side session is not recommended in AEM, you can not cache pages and use proper load balancing if server side session is enabled. Would recommend to save this data to either client context or cookie or query param or Use some kind of session storage (couch base or something). Long run it will help you.

Yogesh 

Avatar

Level 7

Yogesh Upadhyay wrote...

Hello Tuhin,

Using server side session is not recommended in AEM, you can not cache pages and use proper load balancing if server side session is enabled. Would recommend to save this data to either client context or cookie or query param or Use some kind of session storage (couch base or something). Long run it will help you.

Yogesh 

 

Hi Yogesh,

I totally agree with what you are saying. But if I am not wrong we are not form pages are not cached, right? And if the data is not heavy would sticky connection be creating so much performance overhead. It would be only for the forms pages nevertheless. The rest of the pages would be cached. Please correct me if I am wrong.

Thanks

Tuhin

Avatar

Level 3

Thanks yogesh. 

We can not use query parameter as the data is a long string and little sensitive. 

When you say COOKIE, I tried this in my JSP- 

Cookie cookie = new Cookie("key","value");
But I am not able to retrieve this value in my redirected page. Am I doing it right ?