0

I am facing issue while accessing session data in the jsp using struts2 properties tag only for the first time, if I go to another page and come back then session data is assigning fine. By using jsp scriplets in the jsp it is working fine for every time in first instance as well

Action Class code used for setting the session data:

     HttpSession httpSession = ServletActionContext.getRequest().getSession();
     httpSession.setAttribute("userName","User1");

JSP code for reading session data in the JS variable:

     var userName = '<s:property value="#session['userName']"/>';
     var userName1 = '<%=session.getAttribute("userName").toString()%>';

View source Output after page load for the first time:

     var userName = '';
     var userName1 = 'User1';      

View source Output after page load for the second time:

     var userName = 'User1';
     var userName1 = 'User1';  

If its because of syntax is wrong then after second reload also it should not work, if its because the session is not enabled on the jsp page then session.getAttribute should not bring the result in the first time. Can any one please help me in understanding why this is behaving like this is there any thing I am missing or doing wrong.

Thanks,

Vinay
  • 689
  • 3
  • 7
  • 22

0 Answers0