@RequestMapping(value="/login.htm") public ModelAndView login(HttpServletRequest request, HttpServletResponse response) { // show login page if no parameters given // process login if parameters are given } @RequestMapping(value="/index.htm") public ModelAndView index(HttpServletRequest request, HttpServletResponse response) { // show the index page }
Finally, you need a servlet filter to intercept requests, and if you are not requesting the login.htm page, you will need to verify that the user is logged on. If you allow filterchain to continue. If not, you forward /login.htm forward
public class LoginFilter implements Filter { public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpServletRequest = (HttpServletRequest)request; boolean loggedIn = ...;
And in web.xml
Example from my deployment descriptor:
<filter> <filter-name>LoginFilter</filter-name> <filter-class>LoginFilter</filter-class> </filter> <filter-mapping> <filter-name>LoginFilter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> </filter-mapping>
This is all from memory, but this should give you a general idea of how to do this.
source share