hell118232
2009-11-01 11:57权限问题!
public class userfiter implements Filter{
String noFilterURL="";
public void destroy() { }
public void init(FilterConfig arg0) throws ServletException
{
noFilterURL=arg0.getInitParameter("noFilter");
}
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chai) throws IOException, ServletException {
HttpServletRequest request=(HttpServletRequest)req;
String tmpstr=request.getRequestURI().substring(request.getRequestURI().indexOf("/")+1);
String uri=tmpstr.substring(tmpstr.indexOf("/"));
if(noFilterURL.indexOf(uri)<0)
{ HttpSession session=null;
session=request.getSession();
if((session.getAttribute("login"))==null)
{
request.setAttribute("error","请先登录");
RequestDispatcher dis=req.getRequestDispatcher("/login.jsp");
dis.forward(req, res);
return;
}
}
chai.doFilter( req, res);
}
}
UserFilter
com.web.userfiter
noFilter
/login.jsp,/login.do,/images/login_background.gif,
/images/login.jpg,/images/login.bmp-
</init-param>
</filter>
<filter-mapping>
<filter-name>UserFilter</filter-name>
<url-pattern>/*</url-pattern>
这是我写的过滤器,和web.xml的配置文件。但是这没达到我想要的效果,例如我在IE里面http://localhost:8089/OA/login.do,可以提交,但如果把login.do也过滤掉,那就不能登录了!但又不想让直接在IE里面输入http://localhost:8089/OA/login.do提交!还有如果是http://localhost:8089/OA/massge/index.jsp,它是不能登录,可以跳转到http://localhost:8089/OA/login.jsp,但是图片又不显示出来,如果.do提交,返回到http://localhost:8089/OA/login.jsp页面,图片又可能显示出来!
我想的效果是无论从什么方式提交,只要没登录,都要返回到login.jsp页面!当然图片也要显示出来!就是权限问题,没登录,无论你什么方式提交也不能访问其它页面,在怎么做呢?如果用Action做,那.jsp页面就不能过滤掉了,能访问到静态的页面!
要怎么做呢?请帮忙看看!谢谢!给我点意见咯!谢谢...感激不尽!
- 点赞
- 回答
- 收藏
- 复制链接分享
1条回答
为你推荐
- 权限加载问题
- 系统设计
- 0个回答
- 目录树权限加载问题
- it技术
- 互联网问答
- IT行业问题
- 计算机技术
- 编程语言问答
- 0个回答
- linux权限问题
- linux
- 0个回答
- 关于linux系统FTP上传的文件读取权限问题
- linux
- ftp
- 3个回答
- 如何解决网站前台列表的权限问题?
- java
- 前台
- 网站
- 权限
- web
- 7个回答
换一换