首页 > 代码库 > springmvc拦截器
springmvc拦截器
package com.itrus.msign.web; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; import com.itrus.msign.entity.SysAdmin; import com.itrus.msign.json.JSONObject; import com.itrus.msign.web.controller.SysAdminController; public class MyInterceptor extends HandlerInterceptorAdapter { // @Autowired(required=false) // private LicenseCheckService licenseCheckService; public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3) throws Exception { // TODO Auto-generated method stub } public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3) throws Exception { // TODO Auto-generated method stub } public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception { /* * if(request.getRequestURI().endsWith("login.do")){ return true; } * HttpSession session = request.getSession(); * if(session.getAttribute("admin")==null){ * response.sendRedirect("../login.jsp"); return false; } */ // System.out.println("拦截地址PATH:"+request.getContextPath()); // System.out.println("拦截地址URI:"+request.getRequestURI()); String uripath = request.getRequestURI(); // uripath.contains("userList.do") // || uripath.contains("projectList.do") // || uripath.contains("contractList.do") // || uripath.contains("toIndex.do")|| HandlerMethod handlerMethod = (HandlerMethod) arg2; System.out.println("beanClass:" + handlerMethod.getBean().getClass()); Object object = handlerMethod.getBean(); //if (object instanceof SysAdminController) { //((SysAdminController) object).changePassword("admin", "2", "3", //"3", request.getSession(), response); //} if (!uripath.contains("login") && !uripath.contains("API")) { SysAdmin sysAdmin = (SysAdmin) request.getSession().getAttribute( "admin"); if (sysAdmin == null) { String path = request.getContextPath() + "/login.jsp"; response.sendRedirect(path); return false; } else { return true; } } return true; } } DispatcherServlet with name ‘springmvc‘ processing GET request for [/sealserver/contract/contractList.do] Looking up handler method for path /contract/contractList.do Returning handler method [public org.springframework.web.servlet.ModelAndView com.itrus.msign.web.controller.ContractController.contractList(com.itrus.msign.pagenation.ResultFilter<com.itrus.msign.entity.Contract>,java.lang.String,java.lang.String,javax.servlet.http.HttpServletRequest) throws java.io.IOException] Returning cached instance of singleton bean ‘contractController‘ Last-Modified value for [/sealserver/contract/contractList.do] is: -1 beanClass:class com.itrus.msign.web.controller.ContractController Creating a new SqlSession 拦截器可以拦截所有的请求,并且可以获取到该请求访问的controller对象并且可以做一些操作
springmvc拦截器
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。