【发布时间】:2018-09-24 18:22:51
【问题描述】:
我有一个名为 product.jsp 的 jsp 页面。 onload jsp 页面,我需要填充许多下拉列表和其他。但无论成功与否,它都会提交表单,它会清除所有文本字段。 我想保持价值,直到我清楚为止。这是我使用的过程。当我提交它时重定向同一页面但模型属性值变为空。我要保留模型属性值
-
jsp页面
<form:form method="POST" action="/productSetup/add" modelAttribute="productForm"> <spring:bind path="name"> <input type="text" class="form-control" id="name" name="name" value="${productForm.name}" /> </spring:bind> -
这是控制器..
@Controller @RequestMapping("/productSetup") public class ProductController { @RequestMapping(value = "", method = RequestMethod.GET) public ModelAndView index(Model model) { ModelAndView modelAndView = new ModelAndView("product"); model.addAttribute("getCategoryList", dao.getCategoryList()); model.addAttribute("productForm", new ProductModel()); return modelAndView; } @RequestMapping(value = "/add", method = RequestMethod.POST) public ModelAndView usrReg(@ModelAttribute("productForm") ProductModel productModel, Errors error, Model model, HttpSession session,RedirectAttributes redir,BindingResult result) { ModelAndView modelAndView = new ModelAndView("product"); redir.addFlashAttribute("productForm", productModel); return new ModelAndView("redirect:/productSetup"); } }请帮帮我
【问题讨论】:
-
从 jsp 中发布您的整个
<form></form>代码。另请参阅stackoverflow.com/questions/51697296/… 了解更多信息/方向
标签: spring spring-boot spring-security