码迷,mamicode.com
首页 > 编程语言 > 详细

springmvc 设置欢迎页面

时间:2016-05-23 18:58:57      阅读:1141      评论:0      收藏:0      [点我收藏+]

标签:

我的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>

 

springmvc 设置欢迎页面

标签:

原文地址:http://www.cnblogs.com/mabaishui/p/5520998.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!