Spring mvc: best practice to navigate between two jsps

Viewed 9570

I am using spring mvc + spring security to build a simple web application. I implemented the login/logout (spring mvc) but i want to provide also a registration jsp accessible directly from the login.jsp. Basically i just need a simple link from the login.jsp to the regsiter.jsp without passing any parameters or whatever. I just want to ask you what is the best practice to achieve this?

Is there any way to navigate directly between the two jsps without routing the request down to the controller? (or this is not really a spring mvc way?) To be honest my only "problem" is just to have a separate method in the register controller which does nothing just routes the request to the register jsp. I mean:

RegisterController

@Controller  
public class RegisterController {

  @RequestMapping(value="/view_register.htm", method = RequestMethod.POST)
  /** Navigates to the register page */
  public String navigateToRegistration(ModelMap model) {
    return "register";
  }

  @RequestMapping(value="/register.htm", method = RequestMethod.POST)
  /** Handles request from the registration page and registers the user */
  public String registerUser(ModelMap model) {

    // hard stuff to register the user
    return "welcome";
  }

}

WEB-INF/pages/login.jsp

......
<tr>
   <td>Don't have an account yet.</td>
   <td> <a href="<c:url value='view_register.htm' />">Register here</a>
   </td>
</tr>
......

WEB-INF/pages/register.jsp

......
<form name='registration' action="<c:url value='register.htm' />"
        method='POST'>
......

WEB-INF/web.xml - routing each request to spring mvc ...... mvc-dispatcher /

WEB-INF/mvc-dispatcher-servlet

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">

    <import resource="classpath:/applicationContext.xml" />

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>

</beans>

Is my implementation correct? This is the mvc way? I just want to know whether i understand this well and not doing any antipattern stuff. The thing what confuses me is really this additional small method in the regsitration controller which does nothing just navigates from the login to register. Is there at least any naming convention for this kind of methods? Would you recommend rather a ForwardController which could act as a Manager/Dispatcher and would just manage this kind of navigation requests?

1 Answers
Related