la redirección de primavera no cambia la URL del navegador a la URL adecuada

Mi controlador es el siguiente

public class UserController {

private UserService usersService; 

public String users(Model model){
    model.addAttribute("searchUsersDTO", new SearchUsersDTO());
    return "search_for_users_page";

public String search(@ModelAttribute SearchUsersDTO searchUsersDTO,Model model){


    model.addAttribute("usersList", list);
    return "users_list_page";

public String edit(@RequestParam(value="userId") Integer userId,Model model){

    UserDetail detail=usersService.fetchUserDetails(userId);

    model.addAttribute("userDetails", detail);
    return "users_edit_view";

public String save(UserDetailsDTO userDetailsDTO,Model model){

    return "redirect:/users/search";

mapeo de servlet en web.xml

<!-- Processes application requests -->


Frist I will search for users. It will display list of users.
Then I will choose a user to edit,It will display edit view with all details of the user.

Then modify and save the details, which will call save method and after saving the details, should navigate back to search view.

Every thing is working fine. But after saving browser url is displaying as context/users/save, but i required context/users/search.

I figured out the cause of the issues. Need solution.
My users_edit_view ha incluido el and I tried after removing of this lib. Then its working as desired.
Don't know why its causing the issue. And how to solve it.

preguntado el 28 de mayo de 14 a las 12:05

3 Respuestas

The problem (I am excepting ) is with jquery-mobile. I disabled the ajax by adding the following script before the jquery-mobile. Now its working as i desired.

<script type="text/javascript">
 $(document).bind("mobileinit", function () {
    $.mobile.ajaxEnabled = false;
<script src="../js/" th:src="@{/cms/js/}"></script>

podemos agregar data-ajax=false on each form tag.

contestado el 29 de mayo de 14 a las 11:05

Will this be helpful? Spring MVC Controller redirige usando parámetros de URL en lugar de en respuesta

When you return a view name prefixed with "redirect:", Spring MVC transforms this to a RedirectView object anyway, it just does so with setExposeModelAttributes to true (which I think is an odd value to default to).

what if you just use return "redirect: /search" en su lugar?

en realidad, el return "redirect: users/search" you used works in my project.

I think maybe you should bind the object to your model before redirect.

model.addAttribute("usersList", list);

It seem like if you return with a "/" at the beginning, like

return "redirect: /text1/text2"

It will redirect to url context/text1/text2

if you use,

return "redirect: text1"

it will replace the last item in the url, for example, from context/Main/old a context/Main/text1

The only difference between our tests is my controller's Mapping doesn't begin with "/". But even if I change that, it the redirect still works. I have my controller:

@RequestMapping(value = "/Main") or(value = "Main")

both work for

redirect:/Main/    or

contestado el 23 de mayo de 17 a las 12:05

return "redirect: /search" e return "redirect: users/search" wont work as my controller is mapped to /users. Sin embargo, return "redirect:search" is working fine. Actually the data is populating properly in view. issues is with the url only. And I think adding the data to model in save does not make sense. It should bind data in search method. - Raghu Molabanti

well, you are right, it's redirect. I've run some tests, and got something above. - ROROROOROROR

Please check my code in question properly. I used ` redirect:/users/search`. I think I used the right one only. - Raghu Molabanti

I didn't mean you write something wrong in your redirect. So you mean the thing is, "redirect:search" mientras "redirect:/users/search" remains in the same page? - ROROROOROROR

Okay, What would be the cause. I have read many post related to this. :( - Raghu Molabanti

Even induces the same problem and adding data-ajax="false" to the form tag fixes the redirect on the server after POST indeed. Thanks for the tip.

Respondido 02 Jul 16, 03:07

Please refrain from answers that just say "thank you". Several such answers may lock you from posting answers altogether. - grochmal

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.