Hi,
We have to save some user related data in AEM session-storage.
We have one login API and it will fetch user data and store it to session.
In another API we need some of the values in session storage, this API will trigger immediately after login API.
Can we get the session data using
HTTP session =request.getSession();
String userdata = session.getAttribute("userData");
Is it a good Approach?
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @JeevanRaj ,
I think my question was confusing. It is not session-storage.
It is httpSession only and we are able to save to http session and able to get the same.
Issue is resolved.
But thank you so much for the info @JeevanRaj and @Ravi_Pampana
Hi,
If your pages are not cached in dispatcher or any other cdn the request will go to backend and you can read values stored in session storage, but that will increase the load on the publish instances and we need to disabled caching in dispatcher.
You can check Sling Dynamic Include so that only part of the page can be dynamic instead of full page hitting publisher everytime.
Hi @Ravi_Pampana ,
Thanks for the info.
Our first API will set some data in browser Session, that API is actually getting the details of user logged into windows.
Immediately after the first API, we are triggering second one, and it needs some data stored in the session by first login API.
Whenever we load pages both APIs will trigger. So can we use above code to get session data ? or else how can we achieve it. ?
Hi @akhilraj
You cannot get the sessionStorage from SlingHttpServletRequest. You will have to pass the value saved in the sessionStorage to the API. For ex while you are making the ajax call from your JS, you can fetch the value from the sessionStorage and pass it as a query param.
JS snippet:
var someValue = window.sessionStorage.getItem("userName");
$.ajax({
url: "/bin/testServlet?abc=" + someValue,
type: "GET",
dataType: "json",
success: function(data, textStatus, jqXHR) {},
error: function (jqXHR, textStatus, errorThrown) {}
});
Then you can fetch this value on server side through the SlingHttpServletRequest object.
request.getParameter("abc")
Please let me know if this works for you.
Thanks
Jeevan
Hi @JeevanRaj ,
I think my question was confusing. It is not session-storage.
It is httpSession only and we are able to save to http session and able to get the same.
Issue is resolved.
But thank you so much for the info @JeevanRaj and @Ravi_Pampana
Views
Likes
Replies