简体   繁体   English

无法使用路径变量重定向到 Spring MVC 中的另一种控制器方法

[英]Not able to redirect to another method of controller in Spring MVC using path variable

I have one controller class, in which I have two methods.我有一个控制器类,其中有两种方法。 I am submitting a form from jsp ,then control is coming in first method, from first method I am redirecting to second method using path variable, but Its not working.我正在从 jsp 提交表单,然后控制进入第一种方法,从第一种方法我使用路径变量重定向到第二种方法,但它不起作用。

Below is my code:下面是我的代码:

@Controller
public class UserController {

 @RequestMapping(value = "saveUserDetails", method = RequestMethod.POST)
public String saveUser(ModelMap map, HttpSession session,HttpServletRequest request) {
    String strId= request.getParameter("userId");;
    return "redirect:userView/" + strId;
}


 @RequestMapping(value="userView/{id}", method = RequestMethod.GET)
public String displayUser(@PathVariable String id, Model model) {
    System.out.println("in method2");
    return "showUser";
}

}

When user submits the form from jsp then control comes into saveUser() method, there I am redirecting to another method displayUser(), but due to some reason Its not working.当用户从jsp提交表单然后控制进入saveUser()方法时,我正在重定向到另一个方法displayUser(),但由于某种原因它不起作用。 Could anybody please help me ?有人可以帮我吗?

You missed / before userView.您在 userView 之前错过了/

return "redirect:/userView/" + strId;

check spring documentation here 在此处查看弹簧文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Spring MVC在控制器中重定向另一个JSP页面? - how to redirect another jsp page in controller using spring MVC? 当另一个控制器方法在Spring MVC中结束执行时,如何重定向到传递参数的控制器方法? - How can I redirect to a controller method passing a parameter when another controller method end its execution in Spring MVC? 无法从一个控制器重定向到另一控制器-Spring MVC - Unable to redirect from one controller to another controller-Spring MVC 下载或重定向错误消息到 Spring Web MVC 中的另一个控制器操作 - Download or redirect with error message to another controller action in Spring web MVC 在没有页面重定向/刷新的情况下触发 Spring MVC controller 方法 - Triggering Spring MVC controller method without page redirect/refresh 使用spring mvc 3将一个控制器重定向到另一个控制器 - redirecting one to another Controller using spring mvc 3 如何定义路径变量以传递给控制器​​(Spring MVC) - How to define path variable to pass to controller (spring mvc) Spring MVC Controller使用URL参数重定向而不是响应 - Spring MVC Controller redirect using URL parameters instead of in response 使用spring mvc将url模式重定向到特定的控制器 - using spring mvc redirect a url pattern to a specific controller 从一种控制器方法到另一种方法的内部转发(Spring-MVC) - Internal forwarding from one controller method to another (Spring-MVC)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM