I have javascript that calls a function to set the session value like
below is the client code:
<a id="sampleId "href="javascript:confirmTechSimulationSwitch('testLink');
function confirmTechSimulationSwitch(){
var url = window.location.protocol + "//" + window.location.host + "/dummy-proj/Toggle.jsp";
var xmlHttpReq = new XMLHttpRequest();
if (window.XMLHttpRequest) {
xmlHttpReq = new XMLHttpRequest();
xmlHttpReq.open("POST",url, false);
xmlHttpReq.send(null);
}
if (xmlHttpReq.readyState == 4) {
if (xmlHttpReq.status == 200){
var newResponse =xmlHttpReq.responseText.slice(0,4);
if(xmlHttpReq.responseText !=null && newResponse =='true'){
window.location.reload(true);
}
}
}
Inside this Toggle.jsp i have a methood:
<%
System.out.println("inside jsp page");
session.setAttribute("abc","true");
request.setAttribute("abc","true");
request.getSession().setAttribute("abc","true");
System.out.println(" abc123........ "+session.getAttribute("abc"));//prints true
System.out.println("abc456....... "+request.getAttribute("abc"));//prints true
System.out.println("abc789......."+request.getSession().getAttribute("abc"));//prints true
}
%>
now i am trying to fetch this session values after the page reload from the same application in different method as below :
public void Test(HttpServletRequest request){
HttpSession session = request.getSession();
session.getAttribute("abc");// prints null
request.getAttribute("abc");//prints null
request.getSession().getAttribute("abc")//prints null
}
from another java method Test. i get it as null. can anyone please suggest me how to get the session value that is set for abc even after reloading the page?