JSP 如何使用对象收集form表单的信息

来源:互联网 发布:阿里云幕布照片怎么ps 编辑:程序博客网 时间:2024/06/06 05:37

需要使用到的框架spring

jsp页面代码:

<form:form id="form1" name="form1" method="post"action="${turnToSaveOutcomeViewURL}" enctype="multipart/form-data" commandName="oc"><table style="text-align: center; width: 100%;"><tr><td class="tdRight">成果类型:</td><td class="tdLeft"><form:select id="ocType" path="ocType"><form:option value="1">成果类型1</form:option><form:option value="2">成果类型2</form:option></form:select></td></tr><tr><td class="tdRight">成果名称:</td><td class="tdLeft"><form:input id="ocName" path="ocName"/></td></tr><tr><td class="tdRight">获取时间:</td><td class="tdLeft"><form:input id="gotOCDate" path="gotOCDate" onclick="new Calendar().show(document.getElementById('gotOCDate'));"/></td></tr><tr><td class="tdCenter" colspan="2"><a id="submitBtn1" class="majorButton"><span>提交</span> </a></td></tr></table></form:form>


 

后台代码如下:

@RequestMapping(params = "action=turnToCommitView")public ModelAndView turnToCommitView(RenderRequest request,RenderResponse response) {System.out.println(this.getClass() + " ModelAndView turnToCommitView()");ModelAndView mv = new ModelAndView();mv.addObject("oc", new OutcomeVo());mv.setView("commit");return mv;}


 

@RequestMapping(params = "action=turnToSaveOutcomeView",method=RequestMethod.POST)public void turnToSaveOutcomeView(ActionRequest request,ActionResponse response,@ModelAttribute("oc")OutcomeVo oc) throws IOException {System.out.println(this.getClass() + " void turnToSaveOutcomeView()");System.out.println("oc.getOcType():  " + oc.getOcType());System.out.println("oc.getOcName():  " + oc.getOcName());System.out.println("oc.getGotOCDate():  " + oc.getGotOCDate());