0
votes

I am new to Spring MVC. I started out with a login page. So far, I am succeeded in pulling username,password from pre-existing table in my db and validating user at login. Now I want to redirect the user(Who enters wrong credentials) back to same login page with an error message.

My login page is under "web-content" (Web-Content/index.jsp) and the page I access after successful login is under "WEB-INF/views/". But whenever user enters a wrong credential in index.jsp shud b redirected to same page with an error message.

The problem is that the view resolver will resolve the request to page under("WEB-INF/views"). So how can i redirect to page under "web-content" ... Please help.

Thank you so much

1

1 Answers

0
votes

Add default-target-url in your spring config xml file (change login page as per your login page name / URL)

like given below

    <form-login login-page="/index" default-target-url='/homePage'
        authentication-failure-url="/index?login_error=1"
        always-use-default-target="true" />

In Controller add this

@RequestMapping(value="/homePage", method = RequestMethod.GET)
public String printWelcome( ) {

    return "home";

}

Add a jsp page inside views folder as you have view resolver with prefix as WEB-INF/views and (assuming that prefix as jsp)

viewResolver for reference

<bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>