tags:

views:

46

answers:

1

Hello,

Firstly I would like to say that I am quite new to Spring (in particular the MVC framework), and just trying to understand how everything works so please go easy on me.

I'm playing around with a dummy application that I've created, and I've created a simple login form that users can access via the /login.html bean. The bean definition is as follows:

<bean name="/login.html" class="test.controller.LoginController">
    <property name="successView" value="list_messages.html" />
    <property name="commandClass" value="test.domain.Login" />
    <property name="commandName" value="login" />
</bean>

(the Login class is a simple object containing a username and password field with appropriate getters and setters).

The LoginController class does virtually nothing for now:

public class LoginController extends SimpleFormController
{
    @Override
    protected ModelAndView onSubmit(Object command, BindException errors) throws Exception
    {
        return new ModelAndView(new RedirectView(getSuccessView()));
    }
}

Now I have one view resolver in my bean definition file, which goes as follows:

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

To support my Login form I have a login.jsp file in my jsp directory.

My question is as follows: why does accessing /login.html redirect me to login.jsp? I have not specified a formView property for my form, so how does the view resolver know to redirect me to login.jsp?

Thanks in advance for any help!

Joseph.

+1  A: 

When you do not specify The logical view name, Spring relies on DefaultRequestToViewNameTranslator, which is installed by default. So if your request is something like

http://127.0.0.1:8080/app/&lt;LOGICAL_NAME_EXTRACTED_BY_VIEW_NAME_TRANSLATOR_GOES_HERE&gt;.html

Have you seen <LOGICAL_NAME_EXTRACTED_BY_VIEW_NAME_TRANSLATOR> ??? So if your request is

http://127.0.0.1:8080/app/login.html

The logical name extracted by ViewNameTranslator is login which is supplied To viewResolver and Translated To

/jsp/login.jsp

Nothing else

Arthur Ronald F D Garcia
Makes perfect sense - thanks!
Joseph Paterson