Access session storage in Java | Community
Skip to main content
Level 2
Dec 19, 2022 9:05 AM UTC
Solved

Access session storage in Java

Hi All,

I have items in session storage that I want to use in backend.

I have tried Servlet class with get method but was unable to get the item. 

Can anybody with experience help me out ?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
arunpatidar
arunpatidarAccepted solution
New Participant
Dec 19, 2022 10:31 AM UTC

https://sling.apache.org/apidocs/sling11/org/apache/sling/api/SlingHttpServletRequest.html#getCookie-java.lang.String- 

 

Here is the example

 

Cookie countryCookie = slingRequest.getCookie("myCountryCookie"); if(countryCookie==null) { String cookieValue = countryCookie.getValue(); // rest of the logic }

 

https://github.com/arunpatidar02/aem63app-repo/blob/master/java/DemoCookieFilter.java 

Arun Patidar

4 replies

Mani_kumar_
New Participant
Dec 19, 2022 2:38 PM UTC

Once you get the cookie, map all the countries codes which you want to convert or maintain a Generic list in the AEM with all the mappings and get the values from the list

Please find the reference for using generic lists

https://adobe-consulting-services.github.io/acs-aem-commons/features/generic-lists/index.html

 

Hope this is helpful

Translate
arunpatidar
New Participant
Dec 19, 2022 9:34 AM UTC

You cannot access browser session storage at server side, only cookies can be retrieve and updated from backed.

Translate
Arun Patidar
rolliedubAuthor
Level 2
Dec 19, 2022 10:16 AM UTC

.

Translate
arunpatidar
arunpatidarAccepted solution
New Participant
Dec 19, 2022 10:31 AM UTC

https://sling.apache.org/apidocs/sling11/org/apache/sling/api/SlingHttpServletRequest.html#getCookie-java.lang.String- 

 

Here is the example

 

Cookie countryCookie = slingRequest.getCookie("myCountryCookie"); if(countryCookie==null) { String cookieValue = countryCookie.getValue(); // rest of the logic }

 

https://github.com/arunpatidar02/aem63app-repo/blob/master/java/DemoCookieFilter.java 

Translate
Arun Patidar