Hello, I am newbie at Spring. I have an application that uses tiles that I would like to implement an interceptor. I tried to implement it but it's not working
Here is my spring-context.xml
Interceptor class:Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:component-scan base-package="br.com.project.livros" /> <mvc:annotation-driven /> <mvc:resources location="/resources/" mapping="/resources/**"/> <mvc:default-servlet-handler/> <bean class="org.springframework.web.servlet.view.UrlBasedViewResolver" id="tilesViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" /> </bean> <mvc:interceptors> <bean class="br.com.coldsoft.livros.interceptor.AutorizadorInterceptor" /> </mvc:interceptors> <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"> <property name="definitions"> <list> <value>/WEB-INF/tiles-defs.xml</value> </list> </property> </bean> </beans>
LoginController classCode:public class AutorizadorInterceptor extends HandlerInterceptorAdapter { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { String uri = request.getRequestURI(); if (uri.endsWith("loginForm") || uri.endsWith("efetuaLogin")){ return true; } if(request.getSession().getAttribute("usuarioLogado") != null){ return true; } response.sendRedirect("loginForm"); return false; } }
The error is:Code:@Controller public class LoginController { @RequestMapping("logout") public String logout(HttpSession session){ session.invalidate(); return "redirect:loginForm"; } @RequestMapping("loginForm") public String loginForm(){ return "formulario-login"; } @RequestMapping("efetuaLogin") public String efetuaLogin(Usuario usuario, HttpSession session){ if(new UsuarioDao().userExists(usuario)){ session.setAttribute("usuarioLogado", usuario); return "redirect:main"; } return "redirect:loginForm"; } }
My file formulario-login.jsp is at WebContent folderCode:javax.servlet.ServletException: Could not resolve view with name 'formulario-login' in servlet with name 'springmvc
How can I use a Spring Interceptor with Tiles 2.2.2 ? Anyone can help me ?


Reply With Quote