devdar
devdar

Reputation: 5654

Spring MVC Controller Changing URL or Issuing incorrect URL

I have a SpringMVC application i am not sure if its working properly. I have a registration form the url reads http://localhost:8080/myapp/registration.htm when i click on the query button the application is posted to the controller and the user is posted to a second page getList.htm which displays a list of results however when posted to the second page the url still reads http://localhost:8080/myapp/registration.htm.

When the second page is posted the user is suppose to be taken back to the first page http://localhost:8080/myapp/registration.htm to display the record selected form the getList.htm (this displays multiple records).

When the user is posted back to http://localhost:8080/myapp/registration.htm the url reads http://localhost:8080/myapp/getList/1985121244.htm where 1985121244 is the record number. Should the url be displaying http://localhost:8080/myapp/registration.htm once the user is posted back to the first page?

Also if the user tries to POST the first page after being returned form the getList.htm POST you get a HTTP 400 and the url reads http://localhost:8080/myapp/getList/registration.htm. The second page is appended to the url and this is not an appropriate mapping in the controller. Can someone explain what is happening here and how is it fixed.

Edited

Also when i first enter the application the main menu is http://localhost:8080/myapp/hello.htm when i click on a a href i am taken to the registration page however the page shows but the url does not change. When the href tage is clicked form the hello.htm page the Controller makes a reguest to get the registration page and returns it using return new ModelAndView("registration"); i saw some sites that say i should use return new ModelAndView("redirect:/registration"); However when that is used i get 404 Not Found - http://localhost:8080/myapp/registration". Any ideas anyone on what i can look at before i post code my code is alot

Upvotes: 0

Views: 3594

Answers (1)

StanislavL
StanislavL

Reputation: 57381

For me it looks like you just return view name after login. Of course that doesn't change your url. Instead of returning view name use "redirect:/getList.htm" pointing the url you need.

Then controller which processes the getList.htm checks whether user is logged in and return proper view name.

Upvotes: 2

Related Questions