我的项目是ssh,做了过滤器 <!-- 判断登陆的过滤器 -->
<filter>
<filter-name>LoginFilter</filter-name>
<filter-class>
tools.LoginFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>public class LoginFilter implements Filter { protected FilterConfig filterConfig;
protected String encodingName;
protected boolean enable; public LoginFilter() {
encodingName = "GBK";
enable = false;
} // 初始化
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
} // 每个请求设置UTF-8
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding("GBK"); HttpServletRequest httprequest = (HttpServletRequest) request;
HttpServletResponse httpresponse = (HttpServletResponse) response;
HttpSession session = httprequest.getSession();
ActingAdminUser user=new ActingAdminUser();
RequestDispatcher dispatcher=request.getRequestDispatcher("/login.jsp");
String type=request.getParameter("pare");
try { //获得在session中所记录的isLogin属性,该属性由登录部分的代码写入
user = (ActingAdminUser) session.getAttribute("user");
if (user!=null||(httprequest.getServletPath().startsWith("/adminUser.do")&&type.equals("login"))||httprequest.getServletPath().startsWith("/login.jsp")) //验证成功,继续处理
{
chain.doFilter(request, response);
} else //验证不成功,让用户登录。
{
dispatcher.forward(httprequest, httpresponse);
}
} catch (Exception e) {
e.printStackTrace();
}
}
我的里面有上传图片和预览图片的功能,我尝试右键图片看属性复制他的地址http://localhost:8080/项目/image/15/2009/10/17_1255857006.JPG 然后退出浏览器,打开新的页面,没登陆,粘贴到地址栏,可以看到图片
一般这样没什么问题吧,如何需要限制的话过滤器怎么写呢?
<filter>
<filter-name>LoginFilter</filter-name>
<filter-class>
tools.LoginFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>public class LoginFilter implements Filter { protected FilterConfig filterConfig;
protected String encodingName;
protected boolean enable; public LoginFilter() {
encodingName = "GBK";
enable = false;
} // 初始化
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
} // 每个请求设置UTF-8
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding("GBK"); HttpServletRequest httprequest = (HttpServletRequest) request;
HttpServletResponse httpresponse = (HttpServletResponse) response;
HttpSession session = httprequest.getSession();
ActingAdminUser user=new ActingAdminUser();
RequestDispatcher dispatcher=request.getRequestDispatcher("/login.jsp");
String type=request.getParameter("pare");
try { //获得在session中所记录的isLogin属性,该属性由登录部分的代码写入
user = (ActingAdminUser) session.getAttribute("user");
if (user!=null||(httprequest.getServletPath().startsWith("/adminUser.do")&&type.equals("login"))||httprequest.getServletPath().startsWith("/login.jsp")) //验证成功,继续处理
{
chain.doFilter(request, response);
} else //验证不成功,让用户登录。
{
dispatcher.forward(httprequest, httpresponse);
}
} catch (Exception e) {
e.printStackTrace();
}
}
我的里面有上传图片和预览图片的功能,我尝试右键图片看属性复制他的地址http://localhost:8080/项目/image/15/2009/10/17_1255857006.JPG 然后退出浏览器,打开新的页面,没登陆,粘贴到地址栏,可以看到图片
一般这样没什么问题吧,如何需要限制的话过滤器怎么写呢?
解决方案 »
- java Ftp 断点续传下载,不同系统中文乱码和续传错误怎么解决
- 权限设计碰到个问题,大家看看有什么好的方法可以解决?
- 请各位大侠帮帮忙,不知道是什么错照成的
- 请教:hibernate3中调用update()方法将游离状态的customer对象,再次转化成持久化状态后,懒加载全部失效?
- struts2如何实现文件下载??谢谢知道的兄弟帮个忙啊....
- CXF WebService 如何实现GZIP压缩数据
- 怎么使用Log4j时,只把日志文件输出到文件而不输出到控制台的配置文件?
- weblogic中找不到Home接口的问题
- 各位大侠救命啊!dom4j!
- springboot mvn 命令可以正常运行,在idea中使用main启动项运行不了
- 第四行代码什么意思?
- 严重: Exception starting filter opensession!·!!!!! 100分
这个时候 你把他过滤了怎么办 ???
有两种方式 将你的图片放到web-inf下面 外部 不能访问 只有你内部程序能够访问
第二种 判断URL地址是否请求合法 如果不合法 就退回去 其实这个别人可以看你的图片也没什么啊 很多网站的图片都是可以看的