-2
I am studied Java Web and need to make an application with access restriction. Restricting access if the user is not logged in (i.e., the session created), if the user accesses a URL without being logged in, must redirect to the screen login. However I am getting as a response from the browser, that many redirects have been made.
Someone could tell me why you made this mistake?
Authorize ointerceptor.java:
public class AutorizacaoInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object controller) throws Exception {
if(!request.getRequestURI().endsWith("login") && null != request.getSession().getAttribute("userId")){
return true;
}
response.sendRedirect("login");
return false;
}
}
Dispatcher-Servlet.xml:
<context:component-scan base-package="br.com.infnet" />
<mvc:annotation-driven />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
<mvc:resources mapping="/assets/**" location="/assets/"/>
<mvc:interceptors>
<bean class="br.com.infnet.model.AutorizacaoInterceptor" />
</mvc:interceptors>
Please do not paste sprint code screens. Post formatted code and error description instead.
– Anthony Accioly