自定义ajax登录的时候出现的问题
我写了个简单的ajaxlogin登录
情况描述
打开2个页面
第一个页面是ajax登录的页面
第二个页面是登录后收保护的页面
登录第一个页面, 打开受保护的页面2, 在第一个页面登出 并刷新第2个页面由于已经登出就会出现跳到拦截页面CAS的login(这是已经把要跳转的页面存在session里了)
然后在第一个登录页面登录由于第一个页面时ajax请求,并且在session中已经存在他要跳转的页面,所以会返回该跳转的页面,ajax中设置了只能接受json对象因此就会出现登录error其实已经登入了
session中存的跳转URL的格式是
session
{SPRING_SECURITY_SAVED_REQUEST_KEY=SavedRequest[http://localhost:8080/AVerPortal/resourceAction/resourceIndex.action]}
其实这是个请求封装即对于页面http://localhost:8080/AVerPortal/resourceAction/resourceIndex.action的请求
由于是自定义ajaxlogin因此当有拦截目标的时候返回的是一个请求不是一个JSON对象。
解决方案:重写源代码中的AbstractProcessingFilter在验证成功时候使用的 RedirectUtils.sendRedirect类:这个方法顾名思义是像页面发送一个对服务器端页面的请求。response.sendRedirect(response.encodeRedirectURL(finalUrl));
改写成:
StringBuffer str = new StringBuffer();
str.append("{");
str.append("status: \"true\",");
str.append("url: \"");
str.append(finalUrl);
str.append("\"}");
response.getWriter().write(str.toString());
注意这里的我原来写成
StringBuffer str = new StringBuffer();
str.append("{");
str.append("status: true,");
str.append("url: ");
str.append(finalUrl);
str.append("}");
response.getWriter().write(str.toString());
结果在前台却得到
{status: true,url: http://localhost:8080/AVerPortalTest/resourceAction/resourceIndex.action}
{status: true,url: http://localhost:8080/AVerPortalTest/resourceAction/resourceIndex.action}
2份JSON对象原因是因为JSON格式,正确格式如下
{
status:"true",
&nbs
相关文档:
1、创建
XMLHttpRequest
对象的一个实例
var xmlHttp;
function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if ( ......
一.摘要
本系列文章将带您进入jQuery的精彩世界, 其中有很多作者具体的使用经验和解决方案,
即使你会使用jQuery也能在阅读中发现些许秘籍.
本篇文章讲解如何使用jQuery方便快捷的实现Ajax功能.统一所有开发人员
使用Ajax的方式.
二.前言
Ajax让用户页面丰富起来, 增强了用户体验.
使用Ajax是所有Web开发的必 ......
在.net的验证控件中有一个CustomValidator验证控件,其属性ClientValidationFunction为客户端函数,在需要验证的控件失去焦点或者post数据时,调用该函数。
前台:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CustomValidatorTest.aspx.cs" Inherits="Web.CustomValidatorTest" %>
<!DO ......