我写的一个过滤器, 在登录后可以正常使用, 但退出后直接访问页面地址的话, 第一次不经过过滤器, 哪位能够帮忙解决, 在线等
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
HttpServletResponse servletResponse = (HttpServletResponse)response;
HttpServletRequest httpServletRequest = (HttpServletRequest)request;
Object userSession = null ;
try{
userSession = httpServletRequest.getSession(true).getAttribute("user");
System.out.println("session=="+userSession) ;
if (userSession == null) {
String path = httpServletRequest.getContextPath();
servletResponse.sendRedirect(path+"/checkout.html");
}else
chain.doFilter(request, response);
}catch(Exception e){
e.printStackTrace() ;
}
}
这个是我的过滤器的部分代码
各位帮我看看有没有问题
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
HttpServletResponse servletResponse = (HttpServletResponse)response;
HttpServletRequest httpServletRequest = (HttpServletRequest)request;
Object userSession = null ;
try{
userSession = httpServletRequest.getSession(true).getAttribute("user");
System.out.println("session=="+userSession) ;
if (userSession == null) {
String path = httpServletRequest.getContextPath();
servletResponse.sendRedirect(path+"/checkout.html");
}else
chain.doFilter(request, response);
}catch(Exception e){
e.printStackTrace() ;
}
}
这个是我的过滤器的部分代码
各位帮我看看有没有问题
解决方案 »
- SSH中怎样通过getHibernateTemplate()实现分页?
- 求助:怎样获取页面参数?
- structs中没有html:multibox控件!
- 急!!!如何在java类中创建一个web页面,并跳转到该页面
- 包含有隐藏file的FORM为什么提交会出现runtime的错误?急
- web 自动提交
- 100分求分页代码,
- 求 Mysql 和 Oracle for JDBC 源码的下载地址
- ~~~帮帮忙!jsp的疑问!(初学者)~~~
- Hibernate update之后查询结果不稳定
- 小问题:Tomcat embedded版本对SOAP服务支持吗?
- 从Servlet下载文件到Applet,但是不能返回applet,真奇怪
http://blog.csdn.net/wpabbs/archive/2008/08/21/2806677.aspx
部分代码:
// 判断用户是否登录,如果没有,
if (user == null || user.equals("")) {
// 获锝当前的URL
String strURL = sr.getRequestURL().toString();
// 判断是否为index.jsp或userLogin.do
if (strURL.indexOf("/index.jsp") == -1) {
if (strURL.indexOf("/userLogin.do") == -1) {
......