Hi, recently I am trying to use postHandle method in HandlerInterceptor to clean attributes I put in session. My controller is MultiActionController. But the interceptor apply to all methods in controller. Is there any ways I can let it just apply to a specific method in controller? I noticed one of arguments in postHandle is ModelAndView. I set it up as the one to which I want to apply, but it still apply to all methods. Please help me out. Thanks. Following is my action-servlet.xmlFollowing is my postHandleCode:<bean id="methodNameResolver" class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver"> <property name="mappings"> <props> <prop key="/a.html">A_Action</prop> <prop key="/b.html">B_Action</prop> <prop key="/c.html">C_Action</prop> <prop key="/d.html">D_Action</prop> </props> </property> </bean> <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="interceptor"> <list> <ref bean="interceptor"/> </list> </property> <property name="mappings"> <prop key="/a.html">MyController</prop> <prop key="/b.html">MyController</prop> <prop key="/c.html">MyController</prop> <prop key="/d.html">MyController</prop>
Based on example above, the interceptor apply to all methods, but I just want to apply it to C_Action.Code:import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; public class temp extends HandlerInterceptorAdapter{ public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView C_Action) throws Exception { request.getSession().removeAttribute("map"); } }


Reply With Quote