标签:
我的Url pattern 是REST风格的。
<servlet> <servlet-name>leslie-dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>leslie-dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
1、如果你有全局拦截器,请先将拦截器设置为,对"/"放行
/** * 登录拦截器 * */ @Interceptor public class UserLoginInterceptor extends HandlerInterceptorAdapter { private static final String[] IGNORE_URI = { "/","/loginPage", "/checkLogin","/hello" }; @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { // System.out.println("拦截到"); boolean flag = false; String url = request.getRequestURL().toString(); for (String s : IGNORE_URI) { if (url.contains(s)) { flag = true; break; } } if (!flag) { User user = SJLoginController.getLoginUser(request); if (user != null) { // List<String> urls = SJLoginController.getUserRoleUrls(request); // if(urls.contains(url)){ // flag = true; // } flag = true; } } return flag; } }
2、为"/"专门添加一个welcomeController
@Controller public class WelcomeController { @RequestMapping("/") public ModelAndView welcome(){ return new ModelAndView("welcome"); } }
3、在web.xml中添加welcome file
<welcome-file-list> <welcome-file>/</welcome-file> </welcome-file-list>
4、在welcome.jsp页面中跳转到登录页面
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></title> </head> <body> <jsp:forward page="/login/loginPage"></jsp:forward> </body> </html>
标签:
原文地址:http://www.cnblogs.com/mabaishui/p/5520998.html