Spring MVC form Submission

Source: Internet
Author: User

In practice, changes to a single record in a list may require many object parameters to be passed to the background server, and the Spring MVC form label <form:> provides a concise way to submit.

1 <formID= "Form1"class= "Form-horizontal chukong_form"Method= "POST"Action= "${ctx}/channel/sdkversion/postedit.do">3                 <Form:hiddenPath= "Sdkversion.id" />4                 <Divclass= "Form-group">5                     <labelclass= "Col-sm-3 Control-label">Version number</label>6                     <Divclass= "Col-sm-6">7                         <Form:inputPath= "Sdkversion.sdkversion"value= "${sdkversion.sdkversion}"class= "Form-control phone1"ID= "M_version" />8                     </Div>9                 </Div>Ten  One                 <Divclass= "Form-group"> A                     <labelclass= "Col-sm-3 Control-label">Encryption key</label> -                     <Divclass= "Col-sm-6"> -                         <Form:inputPath= "Sdkversion.itemmapperkey"value= "${sdkversion.itemmapperkey}"class= "Form-control phone1"ID= "M_itemkey" /> the                     </Div> -                 </Div> -  -                 <Divclass= "Form-group"> +                     <labelclass= "Col-sm-3 Control-label">Version description</label> -                     <Divclass= "Col-sm-6"> +                         <Form:inputPath= "Sdkversion.desc"value= "${sdkversion.desc}"class= "Form-control phone1"ID= "M_desc" /> A                     </Div> at                 </Div> -  -                 <Divclass= "Modal-footer"style= "Border:none;"> -                     <Divclass= "Col-sm-offset-2 col-sm-6"> -                         <!--<span style= "margin-right:30px;" class= ' label alert-warning ' id= ' Msgflag ' ></span> - -                         <Buttontype= "button"class= "Btn Searchb"ID= "Btn_submit" in Data-loading-text= "Loading ..."AutoComplete= "Off">Mention&nbsp;&nbsp;Make</Button> -                         <aclass= "Btn Searcha"href= "Javascript:history.go ( -1);"style= "margin:2px 1.6% 0;">Return&nbsp;&nbsp;Back</a> to                     </Div> +                 </Div> -             </form>

Form Label
As with any JSP extension tag, before using the Spring form label, you must add a row to the JSP page that references the Spring form label declaration, as follows:

    <%@ Page Language="Java"ContentType="text/html; Charset=utf-8"Pageencoding="UTF-8 "<%@ taglib prefix" form  " Uri= "http://www.springframework.org/tags/form" %>① introduces a label declaration < Html> ... ② declaration, you can use any Spring form label on the page </html>                 
The resulting HTML page is:View Code

Server-side

1 @RequestMapping (value = "/sdkversion/postedit", method =Requestmethod.post)2Public String sdkversionmodify (FinalHttpServletRequest request,3Final model model,FinalSdkversion sdkversion) {4 Sdkversion.setmodifydatetime (NewDate ());5Final User CurrentUser =Sessionmanager.getcurrentuser (Request.getsession ());6 Sdkversion.setmodifyby (NewLong (Currentuser.getid ()). Intvalue ());7Try{8Sdkversionfacade.sdkversionmodify (sdkversion);9}Catch(Appexception Appex) {Ten Debug_logger.error ("Edit sdkversion fail."), Appex);11ThrowNew SystemException (Appex); 12} catch (Exception ex {13 final String error = "edit sdkversion fail." 14  Debug_logger.error (error, ex); 15 throw new16 }17 18 return "Redirect:/channel/sdkversion/query" ;< Span style= "color: #008080;" >19}                 

Where the value of the Sdkversion object in the form form is passed into the background as an object, without having to get the values of each property in the original form, the code is simple and easy to manipulate.

Other than that:

1. Use of check box labels

1Interest:2<Form:checkboxPath= "Favorites"Value= "1"/>Basketball3<Form:checkboxpath= "Favorites"  Value= "2" /> football Span style= "color: #008080;" >4 <form:checkbox = "Favorites"  value = "3" /> read 5 <form:checkbox = "Favorites"  value = "4" /> tour        

2. Use of the Input box label

<Path= "Sdkversion.itemmapperkey" value/>   

3. Use of Radio box labels

1  Gender:<path= "Obj.sex" value= "0"/><path= "Obj.sex" value = "1"/> female           

4. Use of drop-down box labels

1<Form:selectPath= "Obj.city">2<form:option Value= "" label= "--Select--"/> ① suggestive option 3 <form:options  Items= "${citymap}" itemvalue= "key" itemlabel= "value"/>② true option data 4  </form:select>             

Spring MVC form submission

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.