Expand my Community achievements bar.

SOLVED

Pass data between multiple pages

Avatar

Level 1

We have requeement to implement several pages in forms like manner (using forms is out of the scope).

On one page user (anonymous) could fill in some data and by clicking next he could be redirected to another page to enter more data or read some info and continue to next page in the line...

User can go back and forth. On the last page, data that user entered on the previous pages will be used for calculation, maybe generate some graph... 

We could use http session (obviously no caching on dispatcher), maybe cookie if we don't break size limit...

We plan to minimize use of jscript, so using browser local storage is no option.

 

I would like to hear other approaches that could allow us to pass data  between pages.

 

Thank you

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @ukkk 

 

Servlet API provides Session management through HttpSession interface. We can get session from HttpServletRequest object using following methods. HttpSession allows us to set objects as attributes that can be retrieved in future requests.

 

https://www.digitalocean.com/community/tutorials/java-session-management-servlet-httpsession-url-rew... 

View solution in original post

9 Replies

Avatar

Community Advisor

Instead of multiple pages, Cant you do it in single page with multiple Divs which shows the input for the user's data. You can show/hide the divs based on user's click on prev and next using javascript. Finally you can calculate when the last div data is submitted. This requires javascript work.

Avatar

Level 1

Thanks Saravanan,

 

That is known old approach to wizard like pages but I think setting up and maintaining such a page would be a major pain to the authors but it is solution worth considering.

Avatar

Community Advisor

Hi @ukkk 

 

There are two ways to implement the solution and it depends on your use case:-

 

1. Pages URLs are entirely different and requires refresh: Better would be to use session or local storage to capture the field details as cookie size limit is very less 4096 bytes instead session/local storage provides you 5MB of data.

 

2. Single Page : If your entire uses case fits into a single page application and doesn't require refresh, then go with the solution proposed by @Saravanan_Dharmaraj .Simply hide and show the div sections as user click on prev and next. Finally at the end submit the application to do the calculation and generate the graph.

 

Hope this helps.

Avatar

Level 1

Hi Avinash,

 

If we opt for http session approach, does http session in aem behaves same as servlet http session ?

 

Going with spa editor approach, that is a big change for us, as we don't have React experience in the team neather we have built aem app based on spa before, it is just a bad timing to go for it.

 

Thanks

Avatar

Community Advisor

Hi @ukk 

 

I think you can try with using Http session context. Past days, when we were using JSP's we usually set the session context objects in one jsp and read the value in another. Not tried the session approach with slightly though. 

 

First.jsp

String name="Hello";
Session.setAttribute("Name",name);

 

Second.jsp
Session.getAttribute("Name");

 

Why you don't want to leverage the session or local storage approach? It's a very simple and convenient implementation to pass the data from one page to another.

 

Also, I wasn't talking about implementing it in React or Angular.js. You can use the forms wizard approach to show and hide the sections. There is only logic needed on JS side.

Avatar

Level 1

Hi Avinash,

>Why you don't want to leverage the session or local storage approach?

 

If you are talking about http session, that will be probably our approach, I was just wondering on the downsides and some alternatives. We have never used http session on aem projects so we dont know if there are any gotchas ?

Local storage is not an option because we are very limited on using jscript becaus of the project requrements. So most of the logic needs to be coded on the server side.

Avatar

Correct answer by
Community Advisor

Hi @ukkk 

 

Servlet API provides Session management through HttpSession interface. We can get session from HttpServletRequest object using following methods. HttpSession allows us to set objects as attributes that can be retrieved in future requests.

 

https://www.digitalocean.com/community/tutorials/java-session-management-servlet-httpsession-url-rew... 

Avatar

Employee Advisor

You can use the HTTP Session object on the server, but this definitely impacts the scalability of the system; because every page needs to be rendered on the server. And don't forget to use a sticky session approach on the publish side.

 

I would recommend to switch to an SPA approach, and let the user fill all the data in a single "page". And just the final step (form data submission) requires the server end point.

Avatar

Level 1

Thanks Jorg,

 

correct, caching will be impacted.

 

We considered SPA approach but current team doesn't have React/Angular experience and we haven't done any SPA kind of AEM projects, apart from that we require server side rendering which adds additional complexity with Adobe IO involvement.