用Filter过滤登陆验证,怎样把登陆页面和注册页面排除出去呀? 我所有的.jsp直接放在了WebContent里面,所有的Servlet也放在同一个包中了,求指教!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 if(url==登录||url==注册){排除} 匹配url,登陆的注册的就跳过 判断URL是否和注册,登录的一致!如果一致 排除 ,反则验证 在过滤器的配置,添加允许访问的URL字符串参数,,,filter拦截后循环看看是否有指定的URL,有就放行,没有就拦截。 在过滤器中获取uri,对于登陆或者注册页面,放行。 登录页面换成 .html 登陆或注册页面直接放在WebContent下。所有功能界面放WebContent/main下过滤器拦截所有main下即可! 这里的“url”怎么取呢,“登陆”是指完整的可以在浏览器中看到的路劲吗? 这里的“url”怎么取呢,“登陆”是指完整的可以在浏览器中看到的路劲吗?一个很搓的办法就是url.contains("login") 这里的“url”怎么取呢,“登陆”是指完整的可以在浏览器中看到的路劲吗?request.getRequestURL(); 我的doFilter是这样写的,但为什么它都不跳转呢?代码如下:public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req=(HttpServletRequest) request; HttpServletResponse res = (HttpServletResponse) response; HttpSession session=req.getSession(true); String userId=session.getAttribute("userId").toString(); if(userId==null || "".equals(userId)){ res.sendRedirect("http://localhost:8080/libraryManagementSystem/userLogin.jsp"); }else{ chain.doFilter(request, response); } } 最好能区分开呀,我给你一个例子:<filter> <filter-name>sessionFilter</filter-name> <filter-class>com.essp.uas.filter.SessionFilter</filter-class> </filter><filter-mapping> <filter-name>sessionFilter</filter-name> <url-pattern>/application/*</url-pattern> </filter-mapping>上面的过滤去可以过滤所有application目录下的请求 //获取访问地址,如果是登录页面则放行 String path = req.getRequestURI(); System.out.println(path); //验证码图片和js放行 if(path.endsWith("/login.jsp")||path.endsWith("/register.jsp")){ System.out.println("----------"); chain.doFilter(request, response); } 闹钟--再响功能---??求助 请问一个基本的文件上传问题 JAVA EE 和TOMCAT实现全程HTTPS struts2 nexus 如何导入已有的maven构件仓库 WARNING: No request handling method with name 'add' in class [com.zxt.controller 请大虾帮忙,有关jbuilder脚本的出错问题 关于Apache POI开源项目的问题 eclipse + hibernate 数组问题--在线等 axis1 跟axis2问题待高手解决 eclipse 中srping的application.xml没有提示
排除
}
所有功能界面放WebContent/main下
过滤器拦截所有main下即可!
这里的“url”怎么取呢,“登陆”是指完整的可以在浏览器中看到的路劲吗?
这里的“url”怎么取呢,“登陆”是指完整的可以在浏览器中看到的路劲吗?一个很搓的办法就是url.contains("login")
这里的“url”怎么取呢,“登陆”是指完整的可以在浏览器中看到的路劲吗?request.getRequestURL();
我的doFilter是这样写的,但为什么它都不跳转呢?代码如下:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req=(HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
HttpSession session=req.getSession(true);
String userId=session.getAttribute("userId").toString();
if(userId==null || "".equals(userId)){
res.sendRedirect("http://localhost:8080/libraryManagementSystem/userLogin.jsp");
}else{
chain.doFilter(request, response);
}
}
<filter-name>sessionFilter</filter-name>
<filter-class>com.essp.uas.filter.SessionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sessionFilter</filter-name>
<url-pattern>/application/*</url-pattern>
</filter-mapping>上面的过滤去可以过滤所有application目录下的请求
String path = req.getRequestURI();
System.out.println(path);
//验证码图片和js放行
if(path.endsWith("/login.jsp")||path.endsWith("/register.jsp")){
System.out.println("----------");
chain.doFilter(request, response);
}