• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Spring ModelAndView Question

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created my first spring controller without many problems and everything works as I expect except for one item. When I call:



I expect that the URL in my browser would change from login.html to home. The page displays just fine, its just the URL that doesn't change. Does it only change when you use another urlMapping?

Thanks.
 
ranger
Posts: 17344
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well the "view" you return is just a string, it isn't a URL. The String is used by a ViewResolver, to resolve that String to a real view, which might or might not be an html, htm, jsp, Servlet, or any other view technology. So "home" is not necessarily even going to be in the URL.

Mark
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The URL of the new page doesn't show up in the browser because the new page is being sent as the response of the first page's request. The solution to this problem is usually known under the term "redirect after post".

You'll either need to explicitly use a RedirectView or in the controller's bean definition, prepend the successView property with "redirect:". I also think you'll have to use the actual URL and not just a mapping name here.
 
Jon Jensen
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
You save more money with a clothesline than dozens of light bulb purchases. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!