控制用户通过url地址直接访问,需要控制如果用户未登录则跳转到登陆页面 
写了个filter,下为代码片段public class AuthFilter implements Filter {

private static final String LOGIN_URL = "/login.jsp";

public void destroy() {
} public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest)servletRequest;
HttpServletResponse response = (HttpServletResponse)servletResponse;

HttpSession session = request.getSession(true);


String currentURL = request.getRequestURI();
System.out.println("currentURL==========" + currentURL);

String targetURL = currentURL.substring(currentURL.indexOf("/", 1), currentURL.length());  {{注:这快报错java.lang.StringIndexOutOfBoundsException: String index out of range: -1
java.lang.String.substring(Unknown Source)}}

System.out.println("targetURL=" + targetURL);

if (!targetURL.equals(LOGIN_URL)) {
if (session == null || session.getAttribute("user") == null) {
System.out.println("request.getContextPath()=="+ rquest.getContextPath());
response.sendRedirect(request.getContextPath() + "/index.jsp");
return;
}
}
chain.doFilter(request, response);
} public void init(FilterConfig arg0) throws ServletException {
}