我正在使用spring mvc应用程序。我想从控制器或jsp重定向到我在普通servlet和jsps中开发的第二个应用程序。
如何将流程从一个应用程序servlet / jsps导航到另一个应用程序jsp。
我在控制器中使用了以下行来导航:
首先
return new ModelAndView("redirect:/http://localhost:9090/MarathiInput/test.jsp");
第二
response.sendRedirect("http://localhost:9090/MarathiInput/test.jsp");
目前我的控制器是:
@RequestMapping(value = "/transferCertificate", method = RequestMethod.GET)
public ModelAndView get(ModelMap map ,HttpServletResponse response) {
response.sendRedirect("localhost:9090/MarathiInput/test.jsp");
}
在我的jsp中我打电话:
<a href="/transferCertificate" class="sis_nav_link">Generate TC</a> this link
答案 0 :(得分:0)
两次尝试都有小错误,但都可以使用。
假设声明方法控制器返回ModelAndView,您可以使用:
return new ModelAndView("redirect:http://localhost:9090/MarathiInput/test.jsp");
如果声明它返回一个String:
return "redirect:http://localhost:9090/MarathiInput/test.jsp";
或者,如果控制器方法将响应作为参数,您可以在控制器中执行重定向,但是由于您已经处理了响应,因此该方法必须返回null:
response.sendRedirect("http://localhost:9090/MarathiInput/test.jsp");
return null;
所以你可以使用:
@RequestMapping(value = "/transferCertificate", method = RequestMethod.GET)
public ModelAndView get(ModelMap map ,HttpServletResponse response) {
response.sendRedirect("http://localhost:9090/MarathiInput/test.jsp");
return null;
}
或简单地说:
@RequestMapping(value = "/transferCertificate", method = RequestMethod.GET)
public String get(ModelMap map ,HttpServletResponse response) {
return "redirect:http://localhost:9090/MarathiInput/test.jsp");
}
但请确保该链接包含servlet上下文和servlet路径:
<a href="/application/dispatcher_servlet_path/transferCertificate" class="sis_nav_link">Generate TC</a> this link