spring mvc 拦截 后 ajax请求 获取不到session 100
xml配置<beanclass="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHand...
xml 配置
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<list>
<bean class="com.gmako.controller.LoginController"></bean>
</list>
</property>
</bean>
拦截处理类
package com.gmako.controller;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Repository;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
/**
* 后台操作拦截处理类
*
* @author qifu
*
*/
@Repository
publicclass LoginController extends HandlerInterceptorAdapter{
@Override
publicboolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
Object obj = request.getSession().getAttribute("STATUser");
System.out.println("aaaaaa="+obj);
if (obj ==null) {
PrintWriter out = response.getWriter();
StringBuilder builder =new StringBuilder();
builder.append("<script type=\"text/javascript\" charset=\"UTF-8\">");
builder.append("alert(\"页面过期,请重新登录\");");
builder.append("window.top.location.href=\"");
builder.append("admin/Manage_login.jsp");
builder.append("\";</script>");
out.print(builder.toString());
out.close();
returnfalse;
}
returnsuper.preHandle(request, response, handler);
}
} 展开
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<list>
<bean class="com.gmako.controller.LoginController"></bean>
</list>
</property>
</bean>
拦截处理类
package com.gmako.controller;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Repository;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
/**
* 后台操作拦截处理类
*
* @author qifu
*
*/
@Repository
publicclass LoginController extends HandlerInterceptorAdapter{
@Override
publicboolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
Object obj = request.getSession().getAttribute("STATUser");
System.out.println("aaaaaa="+obj);
if (obj ==null) {
PrintWriter out = response.getWriter();
StringBuilder builder =new StringBuilder();
builder.append("<script type=\"text/javascript\" charset=\"UTF-8\">");
builder.append("alert(\"页面过期,请重新登录\");");
builder.append("window.top.location.href=\"");
builder.append("admin/Manage_login.jsp");
builder.append("\";</script>");
out.print(builder.toString());
out.close();
returnfalse;
}
returnsuper.preHandle(request, response, handler);
}
} 展开
展开全部
你的意思是AJAX访问被上面拦截器拦截之后获取不到session吧?
把AJAX访问代码贴出来看看,除非是脚本代码写得不兼容,要不然怎么只有火狐下不能访问呢。你可以用firefox下的firebug,进行断点调试,很好用。
把AJAX访问代码贴出来看看,除非是脚本代码写得不兼容,要不然怎么只有火狐下不能访问呢。你可以用firefox下的firebug,进行断点调试,很好用。
追问
哥们不好意思 我们双休 周一的时候我吧代码给你贴上 你一般什么时候在线啊 还需要你经常指导啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询