I'm having a bit of a bad brain day and was hoping someone kind might help me out. It's probably a shocking simple question. I'm using Spring MVC for the first time (I'm used to Struts), and am trying to create the simplest of login mechanisms, inspired by the one in the JPetstore example. Below is my testapp-servlet.xml:
What should happen is that the LoginInterceptor checks to see whether there is a valid User object contained in the session, and if not, it throws a ModelAndViewDefiningException which causes Spring to reroute to the login JSP. What should then happen is the login controller takes over and checks the details entered. What is instead happening, of course, is that the LoginInterceptor is kicking in for a second time, detecting that the User object is missing and reroutin to the same JSP. So how do I avoid the LoginInterceptor applying when the URL is /login.htm, which is presumably what I need to do?
<beans> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="interceptors"> <list> <ref bean="loginInterceptor"/> </list> </property> <property name="mappings"> <props> <prop key="/test.htm">testController</prop> <prop key="/login.htm">loginController</prop> </props> </property> </bean> <bean id="loginInterceptor" class="testapp.web.LoginInterceptor"/> <bean name="testController" class="testapp.web.TestController"/> <bean name="loginController" class="testapp.web.LoginController"> <property name="dataService" ref="dataService"/> </bean> </beans>