java url中 被过滤_Java开发网 - 帮忙看个限制url访问限制的过滤器实现,用了这个后,图片显示不出来,不知什么原因,...

post.gif于 2004-12-28 18:49

icon_profile.gificon_pm.gificon_quote.gificon_find.gificon_copy.gificon_favorite.gif

帮忙看个限制url访问限制的过滤器实现,用了这个后,图片显示不出来,不知什么原因,

要是不设contentType页面也会乱码,

public class UrlAccessFilter implements Filter {

public void doFilter(ServletRequest request, ServletResponse response,

FilterChain chain) throws IOException, ServletException {

HttpServletRequest httpRequest = (HttpServletRequest)request;

HttpServletResponse httpResponse = (HttpServletResponse)response;

HttpSession session = httpRequest.getSession();

//httpResponse.setContentType("text/html;charset=gb2312");

httpResponse.setContentType(httpRequest.getContentType());

PrintWriter out = httpResponse.getWriter();

System.out.println("进行 URL 访问校验......");

String user = (String)session.getAttribute("CZRY_DM");

if (!user.equals("00000000000")) {

String url = httpRequest.getRequestURL().toString();

for (int i=0; i

if(url.substring(i,i+2).equals("//")) {

url = url.substring(i+2,url.length());

break;

}

}

for (int i=0; i

if (url.substring(i,i+1).equals("/")) {

url = url.substring(i,url.length());

break;

}

}

String urlPage = null;

for (int i=url.length()-1; i>0; i--) {

if(url.substring(i-1,i).equals("/")) {

urlPage = url.substring(i,url.length());

break;

}

}

System.out.println(url);

if (!urlPage.equals("login.jsp")) {

Object obj = session.getAttribute("urlAccess");

if (obj!=null) {

java.util.Vector urlAccess = (java.util.Vector)obj;

boolean pass = false;

for(int i=0; i

String str = (String)urlAccess.get

lightbulb_smile.gif;

System.out.println(str);

if (url.substring(0,str.length()).equals(str)) {

pass = true;

break;

}

}

System.out.println(pass);

if (!pass) {

httpRequest.setAttribute("errorMessage", "您没有访问该页面的权限");

session.setAttribute("errorMessage", "您没有访问该页面的权限");

// out.println("");

// out.println("");

// httpResponse.sendRedirect("/fzgs-fjky/main.html");

httpResponse.sendRedirect("/fzgs-fjky/include/redirect.jsp");

}

chain.doFilter(request,response);

} else {

httpRequest.setAttribute("errorMessage", "您没有被赋于权限,请与您的管理员联系");

session.setAttribute("errorMessage", "您没有访问该页面的权限");

// out.println("");

// out.println("");

// httpResponse.sendRedirect("/fzgs-fjky/main.html");

httpResponse.sendRedirect("/fzgs-fjky/include/redirect.jsp");

}

}

} else {

chain.doFilter(request,response);

}

}

}

我是世界的缔造者!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值