window.location.reload(true) will clear HttpSession?
window.location.reload(true) will clear HttpSession?
我有一个javascript,它调用一个函数来设置会话值,比如
以下是客户端代码:
<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);
}
}
}
在这个Toggle.jsp中,我有一个方法:
<%
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
}
%>
现在,我正试图在页面重新加载后,用不同的方法从同一个应用程序中获取这个会话值,如下所示:
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
}
来自另一个java方法Test。我把它记为空。有人能建议我如何在重新加载页面后获得为abc设置的会话值吗?
首先让我们回答这个标题:不,它不会使服务器的会话无效——错误不在这里。
第二:这有什么意义?
if(res !=null && res =='true'){
var res="true";
[..]
}
做这个没有意义
最后,我们需要更多的信息,以便最终解决您的问题。比如触发javascript执行的条件,或者javascript周围的整个HTML(如果它包含在页面中)。
相关文章:
- Clear Case.如何在多行上拆分很长的javascript
- WIll window.addEventListener(“加载”,function(),false);等待浏览器自动填
- SVG Clear group<g>
- Will my'新对象'在套接字断开连接时被垃圾收集
- Clear __eventArgument
- 名为“;清除“;没有被呼叫.尝试呼叫“;clear()”;使用内联js
- window.location.reload(true) will clear HttpSession?
- 我想在单击clear链接时使用javascript中的拼接删除整个列表
- clear().sendKeys() 两次在量角器中失败
- 响应菜单 js (clear dom?)
- 为什么 clear() 函数在发生 onChange 事件时没有被调用
- My localStorage.clear(); won't work
- 使用 localstorage.clear() 但排除 1 个项目
- clear悬停时的间隔,如果元素具有特定的背景
- Will var result = function() { //doSomething };if (result !=
- javascript onmouseout clear html element
- 我的功能”;clear()”;没有接到电话
- d3.js使用brush.clear();It’我不管用
- 在 StorageArea.clear 之后未调用第二个警报
- Will'http:url'适用于所有浏览器和设备