[英]how to redirect another jsp page in controller using spring MVC?
in WEB-INF having a Jsp File pls see image I am using Spring mvc with Hibernate Database connection,in my controller having data from database in variable val
now how can i redirect to another jsp page with data's 在具有Jsp文件的WEB-INF中请参见图像 我正在使用带有休眠数据库连接的Spring mvc,在我的控制器中具有来自变量val
数据库的数据的现在如何重定向到具有数据的另一个jsp页
Controller Part: 控制器部分:
@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";
}
You can pass data from controller to UI(another JSP page) with the help of ModelAndView in Spring. 您可以在Spring中借助ModelAndView将数据从控制器传递到UI(另一个JSP页面)。
new ModelAndView("newJSPPage","aliasNameToBean",originalBean);
newJSPPage - replace with the new JSP file which you need to redirect from the controller. newJSPPage-替换为需要从控制器重定向的新JSP文件。
aliasNameToBean - replace with the alias name which you can access bean data at redirected JSP page. aliasNameToBean-替换为别名,您可以在重定向的JSP页面上访问bean数据。
originalBean - replace with the original bean object name which you have the data. originalBean-用您拥有数据的原始bean对象名替换。
return "redirect:/EditShop.jsp"; 返回“重定向:/EditShop.jsp”;
Insted of this you have return View Name like return "EditShop"; 为此,您需要返回View名称,例如return“ EditShop”;
In Spring Execution Flow InternalResourceViewResolver will Take Care to Call Jsp. 在Spring执行流中,InternalResourceViewResolver将注意调用Jsp。
you have to set val to HttpSession Object like session.setAttribut("val",valueofField); 您必须将val设置为HttpSession对象,例如session.setAttribut(“ val”,valueofField);
Then you get that value In your jsp session.getAttribute("val"); 然后,在jsp session.getAttribute(“ val”);中获得该值。
I Hope it helps. 希望对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.