use Spring's form labels
SPRINGMVC form labels enable you to bind attributes and HTML form elements in model data to enable easier editing of form data and echo of form values
Form label
• In general, get form pages through get requests and submit form pages via post requests, so the URL to get form pages and submit form pages is the same. As long as the contract for the best condition is met, the <form:form> tag does not have to pass the Act to get the form page through a GET request, and the form page is submitted via a POST request, so the URL to get the form page and submit the form page is the same. The <form:form> tag does not need the ion attribute to specify the URL of the form submission as long as the contract for that best condition is met
• The model property of the binding can be specified through the Modelattribute property, and if this property is not specified, the form bean that reads command from the request domain object is defaulted, and an error occurs if the property value does not exist.
Corresponding handler model attributes are consistent with Modelattribute
Form Labels
SPRINGMVC provides multiple form component labels, such as <form:input/>, <form:select/>, to bind the attribute values of form fields, and their common properties are as follows:
–path: Form fields, corresponding to the Name property of the HTML element, support cascading properties
–htmlescape: Whether to convert the HTML special character of the form value to the default value of True
–cssclass: CSS style class name corresponding to form component
–csserrorclass: The CSS style taken when there is an error in the data of the form component
form:input, Form:password, Form:hidden, Form:textarea: text, password, hidden, textarea tags corresponding to HTML forms
Form:radiobutton: A radio box component label that is selected when the form bean corresponds to a property value and a value equal
form:radiobuttons: A radio box Group label for constructing multiple radio boxes
–items: Can be a List, string[] or Map
–itemvalue: Specifies the value of the radio. Can be a property value of a bean in a collection
–itemlabel: Specifies the label value of the radio
–delimiter: Multiple Radio boxes can specify delimiters by delimiter
form:checkbox: check box component. Used to construct a single check box
Form:checkboxs: Used to construct multiple check boxes. Using the same form:radiobuttons label
form:select: Used to construct a drop-down box component. Using the same form:radiobuttons label
form:option: drop-down box option component label. Using the same form:radiobuttons label
form:errors: Displays errors for the form component or data check
–<form:errors path= "*"/>: Display all errors in the form
–<form:errors path= "user*"/>: Displays all errors that correspond to the user-prefixed attribute
–<form:errors path= "username"/>: Error displaying properties of specific form objects
working with Static resources
• Elegant REST-style resource URLs do not want to bring. html or. Do suffixes
• If the Dispatcherservlet request mapping is configured AS/, Spring MVC captures all requests for the Web container, including requests for static resources, and SPRINGMVC treats them as a normal request, which causes an error if the corresponding processor is not found.
• Workaround: You can configure <mvc:default-servlethandler/> in the SPRINGMVC configuration file to resolve static resource issues:
–<mvc:default-servlet-handler/> will define a Defaultservlethttprequesthandlerin the SPRINGMVC context, which will enter the Dispatcherservlet Request for screening, if the discovery is not mapped to the request, the request to the Web application server default Servlet processing, if not a static resource request, Dispatcherservlet continue processing
– The name of the default Servlet for the general WEB application Server is defaults. If the default Servlet name for the Web server you are using is not default, you need to explicitly specify it through the Defaultservlet-name property
Attention:
Controller and view are commonly used in SPRINGMVC. However, we often need to access static resources, such as html,js,css,image. The URL of the default access is blocked by Dispatcherservlet, but we want the static resource to be accessible directly. What about the swelling? Static resource access, in fact, a variety of methods, such as: Through the open Tomcat Defaultservlet, modify the default Url-parttern. But Springmvc provides a more convenient way to handle static resources.
Solution:
Add a resource map directly in the Spring-mvc.xml.
Resource Mapping
<!--access to static resources (Js/image)--
<mvc:resources mapping= "/css/**" location= "/css/"/>
<mvc:resources mapping= "/images/**" location= "/images/"/>
<mvc:resources mapping= "/js/**" location= "/js/"/>
Mapping: Mapping
Location: Local resource path, note must be the path under the WebApp root directory.
Two *, which represents all URLs under the map resources/, including sub-paths (that is, multiple/) so that we can directly access the static content under the folder.
The following resources can be accessed directly:
Http://localhost:8090/firstapp/images/cookie.png
Http://localhost:8090/firstapp/js/jquery-1.11.2.js
SPRINGMVC form Labels & handling static resources