SPRINGMVC Form Label

Source: Internet
Author: User
Tags html form

Use form tags to develop form pages more quickly and to make it easier to echo form values
Attention:
You can specify the model properties of a binding by using the Modelattribute property.
If this property is not specified, the default form bean that reads command from the request domain object
If the property value also does not exist, an error occurs.

Instance

<%@ taglib prefix= "form" uri= "Http://www.springframework.org/tags/form"%>
<%@ taglib prefix= "C" uri= "Http://java.sun.com/jsp/jstl/core"%>

<form:form action= "${pagecontext.request.contextpath}/emp" method= "POST"
Modelattribute= "Employee" >

<form:errors path= "*" ></form:errors>
<br>

<c:if test= "${employee.id = = null}" >
<!--the Path property corresponds to the Name property value of the HTML form label--
LastName: <form:input path= "LastName"/>
<form:errors path= "LastName" ></form:errors>
</c:if>
<c:if test= "${employee.id! = null}" >
<form:hidden path= "id"/>
<input type= "hidden" name= "_method" value= "PUT"/>
<%--cannot use the Form:hidden tag for _method because Modelattribute does not have _method in the corresponding bean--%>
<%--
<form:hidden path= "_method" value= "PUT"/>
--%>
</c:if>

<br>
Email: <form:input path= "Email"/>
<form:errors path= "Email" ></form:errors>
<br>
<%
map<string, string> genders = new HashMap ();
Genders.put ("1", "Male");
Genders.put ("0", "Female");

Request.setattribute ("genders", genders);
%>
Gender:
<br>
<form:radiobuttons path= "Gender" items= "${genders}" delimiter= "<br>"/>
<br>
Department: <form:select path= "Department.id"
items= "${departments}" itemlabel= "Departmentname" itemvalue= "id" ></form:select>
<br>

Birth: <form:input path= "Birth"/>
<form:errors path= "Birth" ></form:errors>
<br>
Salary: <form:input path= "Salary"/>
<br>
<input type= "Submit" value= "Submit"/>
</form:form>

SPRINGMVC Form Label

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.