Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9047641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:57:35+00:00 2026-06-16T11:57:35+00:00

I have a Spring MVC Controller with handlers like so: @RequestMapping(value = /account/login, method

  • 0

I have a Spring MVC Controller with handlers like so:

@RequestMapping(value = "/account/login", method = RequestMethod.GET)
public String login() {
    return "login";
}


@RequestMapping(value = "/account/login", method = RequestMethod.POST, params = "login")
public String login(@RequestParam(value = "username") String username, 
        @RequestParam(value = "password") String password) {

    // do authentication
    return "home";
}

The form in the login.html page POSTs to account/login (the same url). I’d like that after the authentication, I redirect the user to the home page of my application, so that he sees www.mywebappexample.com in address bar instead of www.mywebappexample.com/account/login. When I return the string from the login method, it renders the proper html but I don’t have the URL I want to show. How can I redirect?

Edit: I had to prefix my controller return String with redirect:. This works if you have a view resolver that subclasses UrlBasedViewResolver UrlBasedViewResolver. Thymeleaf’s view resolver doesn’t do that but it does have the behavior -> ThymeleafViewResolver. Here’s my servlet-context.xml (I’m using thymeleaf):

<bean id="templateResolver"
      class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
    <property name="prefix" value="/WEB-INF/"/>
    <property name="suffix" value=".html"/>
    <property name="templateMode" value="HTML5"/>
</bean>

<bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine">
    <property name="templateResolver" ref="templateResolver"/>
</bean>

<bean id="viewResolver" class="org.thymeleaf.spring3.view.ThymeleafViewResolver">
    <property name="templateEngine" ref="templateEngine"/>
    <property name="order" value="1"/>
</bean>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T11:57:37+00:00Added an answer on June 16, 2026 at 11:57 am

    You can use a redirect in the tag instead which should update the URL in the browser window:

    return "redirect:home";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have spring mvc controller, contain method like @requestmapping(jsps/welcome.jsp) public String handleRequest(){ system.out.println(inside the
I have a Spring MVC Controller class (bean): @Controller @RequestMapping(/index.jsp) public class EjbCaller {
I have a basic Spring MVC controller that looks like this: @Controller public void
I have a spring mvc controller that returns a pojo : @RequestMapping(value = /person,
I have a controller (Spring-MVC) that generates a PDF report on a get request.
I'm running Spring MVC 3.x and I have one Controller with RequestMapping annotations (
In my MVC controller I have a handler method with a signature: public void
I'm having a strange problem with Spring MVC. I have a simple controller like
I have a doubt about Model behavior in Spring MVC. I have a controller
I have a Spring Web MVC application that I'd like to serve a large,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.