怎样写一个servlet过滤器防止别人跳过登陆框直接进入系统?
哪个有源代码给我看看。。。。
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse rep = (HttpServletResponse) response;
try {
Object o = req.getSession().getAttribute("login");
String url = req.getRequestURI();
if (o == null) {
if (url.contains("servlet")) {
req.getRequestDispatcher("servlet").forward(req, rep);
return;
}
req.getRequestDispatcher("index.jsp").forward(req, rep);
}
else {
int point = url.lastIndexOf("/");
String str = url.substring(point);
req.getRequestDispatcher(str).forward(req, rep);
}
}
catch (Exception ex) {
ex.printStackTrace();
}
这样做 好象没什么好处,每一个请求都要被过滤一下,包括表单提交 而且由表单post提交过来的路径request也没法请求分派。
[此贴子已经被作者于2007-5-28 9:52:33编辑过]