当所有请求都进行过滤拦截,你是不能登录的,你把登录的url放行,登录后能看的页面进行过滤
解决方案 »
- javaee表单配置问题
- IntelliJ IDEA rebulid项目时会删除webroot下的部分文件怎么处理
- 求教MyEclipse8.6配置Tomcat问题?
- 依赖注入---空指针异常
- 请帮忙解析Exception in thread "main" java.lang.NoClassDefFoundError
- 用SmartUpload上传的时候,在mySmartUpload.upload()老是过不去?
- 请问什么是POJO?在书写一个POJO的时候有什么规范么?
- 询问上海的对日开发j2ee薪水行情
- 一个关于EJB的奇怪的问题
- JAVA MAP里的VALUE算数计算优化
- 求帮忙java正则匹配
- dbcp连接池问题java.lang.AbstractMethodError: com.mysql.jdbc.Connection.isValid(I)Z
String uri = request.getRequestURI();
把这句改为
String uri = request.getServletPath()试试
所有的请求通过拦截器去拦截,所有的页面通过过滤器去拦截,我之前写过一个小demo,参考一下:@Override
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
String path = request.getServletPath(); HttpSession session = request.getSession();
// 如果已经登录
if (session.getAttribute("userId") != null) {
chain.doFilter(req, res);
return;
}
// 如果是登录等地址
if ("/login.jsp".equals(path) || "/checknum.jsp".equals(path)) {
chain.doFilter(req, res);
return;
}
// 禁用浏览器缓存
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);
String contextPath = request.getContextPath();
response.sendRedirect(contextPath + "/login.jsp");
}最后提醒你一下~ 在web.xml中过滤器要配置在struts核心控制器前面~ 一般sturts的都会配置拦截所有请求~