要求:当我点击我的网络应用程序中的重置按钮时,它不会显示重新验证弹出窗口。
HTML code:
<button type="reset" onclick="reloadcurrentpage(false)">Reset</button>
JS代码
function reloadcurrentpage(isAuthenticationRequired){
window.location=window.location.href+"?isAuthenticationRequired"+isAuthenticationRequired;
}
我有UserAuthenticationFilter,它看到如果页面已经过身份验证。我这样做是通过将boolean值存储到会话范围内的某个变量进入Controller时进行的。 让我让你更清楚。我们假设它是第一次验证
控制器代码
public class MyController{
public Object formBackingObject(HttpServletRequest request){
request.getSession.setAttribute("isAuthenticated",true)
}
}
过滤代码:
public class Fitler{
doFilter(request,response,filterChain){
if(request.getSession.getAttribute("isAuthenticated")){
request.getSession.remove("isAuthenticated");
fitlerChain.doFilter(request,response) ;
}else{
reponse.sendRedirect("showAuthenticationPopUp")
}
}//doFilter ends//
}//filter class ends
我遵循的方法是为了避免重新验证
1)当我点击重置时说URL构成是 http.india.com/myController?isAuthenticationRequired=false 其他时候 http.india.com/myController
现在,当我单击“重置”按钮并在此查询字符串的过滤器中写入适当的代码时,我可以避免重新身份验证,但问题是当我刷新页面时,还会避免重新身份验证,这不应该发生。原因是当我点击重置时形成的url是 http.india.com/myController?isAuthenticationRequired=false 所以每次刷新页面时都会避免重新验证,这将是另一个问题。
2)我遵循的第二种方法是当URL具有该参数然后我调用
response.redirect(request.getURI());
这被查询字符串删除,但它让我再次验证页面。
3)我遵循的第三种方法是使用它为我工作的Ajax请求,但证明代价高昂,因为我必须更改45个以上的重新认证文件并调整响应。
请为此提出一些建议。
答案 0 :(得分:0)
在页面加载时,我使用历史记录对象从浏览器中删除URL。
if(location.search.contains("isAuthenticationRequired=false")){
history.replaceState(null,documnent.title,location.pathname)
}