标签:
http://localhost/SSM 默认进入的是登陆页,如果登陆过后,再进入 http://localhost/SSM ,应该让它进入首页。
我们可以直接在web.xml 配置 user/main.do
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>SSM</display-name> <welcome-file-list> <welcome-file>user/main.do</welcome-file> </welcome-file-list> </web-app>
以下是拦截器配置
package com.gj.filter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.ModelAndView; import com.gj.model.User; public class LoginInterceptor implements HandlerInterceptor { //private Logger logger = Logger.getLogger(LoginInterceptor.class); private static final String[] IGNORE_URI = {"/login","wechat","register","checkUsernameRepeat","save"}; @Override public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3) throws Exception { // TODO Auto-generated method stub } @Override public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3) throws Exception { } @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj) throws Exception { boolean flag = false; String url = request.getRequestURL().toString(); System.out.println(">>>: " + url); for (String s : IGNORE_URI) { if (url.contains(s)) { flag = true; break; } } if (!flag) { User user = (User) request.getSession().getAttribute("currentUser"); if (user != null) { if(null==user.getWechat_num_type() && url.indexOf("preSave.do")>-1 && url.indexOf("user") < 0){ flag = false; request.getSession().setAttribute("info","true"); response.sendRedirect(request.getContextPath()+"/user/preSave.do"); } else { flag = true; } } else { response.sendRedirect(request.getContextPath()+"/login.jsp"); } } return flag; } }
如果发现 http://localhost/SSM 是404错误的话,在代码没有问题的情况下,确认是否是tomcat7以上。
总结一句话:如果你的环境是SpringMVC,想在web.xml配置 直接跳转SpringMVC的链接,tomcat一定要是7以上
标签:
原文地址:http://my.oschina.net/gengjie2/blog/379943