The JSP page needs to be introduced:<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>标签.
Text box:
<td><form:label path= "Name" > Name: </form:label></td><td><form:input path= "Name"/ ></td>
Password box:
<td><form:label path= "username" > User name: </form:label></td><td><form:input path= " Username "/></td>
Text fields:
<td><form:label path= "Address" > Add: </form:label></td><td><form:textarea path= " Address "rows=" 5 "cols="/></td>
check box:
<td><form:label path= "Receivepaper" > Subscribe to News? </form:label></td><td><form:checkbox path= "Receivepaper"/></td>
check boxes (multiple selections) need to be in use with the backend Java:
@ModelAttribute ("webframeworklist") public list<string> getwebframeworklist () { list<string > webframeworklist = new arraylist<string> (); Webframeworklist.add ("Spring MVC"); Webframeworklist.add ("Spring Boot"); Webframeworklist.add ("Struts 2"); Webframeworklist.add ("Apache Hadoop"); return webframeworklist; }
<form:checkboxes items= "${webframeworklist}" path= "Favoriteframeworks"/>
radio button:
<Form:radiobuttonPath="Gender"Value="M"Label= "male " /><< Span class= "token namespace" >form:radiobutton path< Span class= "token punctuation" >= "Gender" value=" F "label = "female " />
Multiple radio buttons (need to be in use with back-end Java):
@ModelAttribute ("numberslist") public list<string> getnumberslist () { list<string> Numberslist = new arraylist<string> (); Numberslist.add ("1"); Numberslist.add ("2"); Numberslist.add ("3"); Numberslist.add ("4"); return numberslist; }
<form:radiobuttons path= "Favoritenumber" items= "${numberslist}"/>
Drop-down list: You need to use the backend code:
@ModelAttribute ("countrylist") public map<string, string> getcountrylist () { map<string, string> countrylist = new hashmap<string, string> (); Countrylist.put ("US", "states"); Countrylist.put ("CH", "China"); Countrylist.put ("SG", "Singapore"); Countrylist.put ("MY", "Malaysia"); return countrylist; }
<form:select path= "Country" > <form:option value= "NONE" label= "select"/> <form:options items = "${countrylist}"/></form:select>
Multiple list check box:
@ModelAttribute ("skillslist") public map<string, string> getskillslist () { map<string, String > skilllist = new hashmap<string, string> (); Skilllist.put ("Hibernate", "Hibernate"); Skilllist.put ("Spring", "Spring"); Skilllist.put ("Apache Hadoop", "Apache Hadoop"); Skilllist.put ("struts", "struts"); return skilllist; }
<form:select path= "Skills" items= "${skillslist}" multiple= "true"/>
Hidden fields:
<form:hidden path= "id" value= "/>"
Spring MVC error Handling:
<form:errors path= "*" cssclass= "errorblock" element= "div"/>
Upload file:
<form:form method= "POST" modelattribute= "fileUpload" enctype= "Multipart/form-data" > Please select a file upload: <input type= "file" name= "file"/> <input type= "Submit" value= "Submit upload"/> </form:form>
This is used value =“fileUpload”
modelAttribute
to map the file with the property to upload the control with the server model.
Spring MVC: Common tag Library (text box, password box, text field, check box, radio button, drop-down box hidden, upload file, etc.)