in WEB-INF having a Jsp File pls see image 我正在使用 Spring mvc 和 Hibernate 数据库连接,在我的 Controller 中,变量 val
中有来自数据库的数据,现在我如何重定向到另一个带有数据的 jsp 页面
Controller 部分:
@RequestMapping(value = "/EditShop" , method = RequestMethod.POST)
public String editShop(HttpServletRequest request,HttpServletResponse response) throws IOException
{
String id=request.getParameter("Id");
try
{
String val=shopService1.editShopinfo(id);
System.out.println("Edit Shop : "+val);
}
catch(Exception e)
{
System.out.println("Edit Shop : "+e );
}
return "redirect:/EditShop.jsp";
}
最佳答案
借助 Spring 中的 ModelAndView,您可以将数据从 Controller 传递到 UI(另一个 JSP 页面)。
new ModelAndView("newJSPPage","aliasNameToBean",originalBean);
newJSPPage - 替换为您需要从 Controller 重定向的新 JSP 文件。
aliasNameToBean - 替换为您可以在重定向的 JSP 页面访问 Bean 数据的别名。
originalBean - 替换为您拥有数据的原始 bean 对象名称。
关于java - 如何使用 Spring MVC 重定向 Controller 中的另一个 jsp 页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47089059/