我服务设置的session过期时间是5分钟。
5分钟不用之后,再去刷新页面。应该跑到的是登陆页面里面去(设置了过滤器)。但是没到登陆页面里面去,也没到过滤器里面去
是什么问题??
刷新之后直接跑到了:http://localhost:7070/login.jsp
项目的路径没了。本来应该是:http://localhost:7070/test/login.jsp
过滤器里面是这样子写的:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
// TODO 自动生成方法存根
HttpServletRequest req = (HttpServletRequest)request;
HttpServletResponse res = (HttpServletResponse)response;
HttpSession session = req.getSession();
// System.out.println("++++++++++++++++++="+context);
//设置application属性
if(session.getAttribute("person")==null)
{
//未登录,跳转到登录界面
String context = req.getContextPath();
System.out.println("++++++++++++++++++="+context);
String url = context + "/login.jsp";
// res.sendRedirect(url);
req.getRequestDispatcher("/login.jsp").forward(req, res);
}else
{
chain.doFilter(request,response);
}
}
web.xml里面是这样子的:
<filter>
<filter-name>LoginFilter</filter-name>
<filter-class>com.landi.filter.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>/index.jsp</url-pattern>
</filter-mapping>
你没用别的框架吧?
你照我的做法:
1,在你的webroot新建一个admin的文件夹,把你需要登录才能访问的页面放进去。
2,
[code="xml"]
LoginFilter
/admin/*
[/code]
3,把你的一些路径相应改一下,然后自己跑起来试试,你不试我给你解释很多东西你还是不明白。
改成[code="java"]String url = context + "/test/login.jsp";[/code]
req.getRequestDispatcher("/login.jsp").forward(req, res);
你的上下文路径是/test吗?如果是这样的话,那写成
req.getRequestDispatcher("login.jsp").forward(req, res);
这样是相对对上下文路径的。
如果是/login.jsp,这是绝对路径。
还有一种做法是将你的上下文路径修改为/而不是/test,当然前提是需要保证这样的路径设置不会引起冲突。
晕 你过滤器怎么拦截的index.jsp啊
[code="xml"]
LoginFilter
/index.jsp
[/code]
你应该拦截那些需要登录的连接。比如你把需要登录的连接放到/admin这个文件夹下 然后了配制成/admin/* 那么所有这个目录下的jsp或者连接包含/admin/的一下的action都会拦截。
[code="xml"]
LoginFilter
/index.jsp
[/code]
这个配置就代表着你将要拦截index.jsp,建议把这个换一下。
你的过滤器没有进去 是因为你访问的连接没有被拦截,而没有被拦截的原因是你的配置问题,你看看你的配置
[code="xml"]
LoginFilter
/index.jsp
[/code]
说明你只拦截了index.jsp 其他的你都没有拦截。