Process Text Overview
1, the user sends the request to the front controller Dispatcherservlet
2. Dispatcherservlet received a request to call the Handlermapping processor mapper.
3. The processor mapper finds the specific processor, generates the processor object and the processor interceptor (if any) is returned to Dispatcherservlet.
4. Dispatcherservlet Call Handleradapter Processor Adapter
5, Handleradapter through the adaptation of the call to the specific processor (controller, also known as the back-end controller).
6, controller execution completed return Modelandview
7, Handleradapter the controller execution results Modelandview returned to Dispatcherservlet
8. Dispatcherservlet Pass Modelandview to Viewreslover view parser
9, Viewreslover after parsing return to the specific view
10. Dispatcherservlet the rendered view based on the view (populate the model data into the view).
11. Dispatcherservlet Response User
2. How to solve the problem of POST request Chinese garbled,GET and How to deal with it?
Add to Web. xml:
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
The above can solve the POST request garbled problem. There are two garbled methods for GET request Chinese parameter:
Modify the Tomcat profile add code to match the project code as follows:
<connector uriencoding= "Utf-8" connectiontimeout= "20000" port= "8080" protocol= "http/1.1" redirectport= "8443"/ >
Another way to re-encode parameters:
String userName = new String (Request.getparamter ("UserName"). GetBytes ("Iso8859-1"), "Utf-8")
Iso8859-1 is the tomcat default encoding, and the Tomcat encoded content needs to be encoded by utf-8
S
Pringmvc and struts
The difference of 2
1, Springmvc 's entrance is a servlet is the front controller, and the struts2 entrance is a Filter filter.
2, Springmvc is based on method development, and struts2 is based on class development .
The SPRINGMVC maps the URL and Controller methods . After the mapping succeeds , SPRINGMVC generates a Handler object with only one method in the object . The method execution ends and the shape parameter is destroyed.
3, Springmvc can be a single case development , and recommended a single case .
the Struts2 receive parameter is received through the member variable , cannot use the singleton , can only use multiple examples .
4, after the actual test,struts2 slow, in the use of struts label, not because of the single case or a number of problems.
if using struts, it is recommended to use jstl.
5, Struts2 There is a loophole ,springmvc At present no loopholes appear .
If you use struts2, it is recommended to download the latest package .
A few common annotations in SPRINGMVC
@RequestMapping (value= "/item/param/{itemid}", produces=mediatype.text_html_value+ "; Charset=utf-8")
Value: Set the path you want to go to
Produce: Setting the response encoding
{itemId}: the name of the parameter that represents the request is called itemId .
@ResponseBody
added to the method, indicating the return Json -formatted data
@PathVariable (VALUE=ITEMID) Long ID
In conjunction with the first note, there is a restful style , if the ID is changed to ItemId, Then you can omit the value=itemid, the annotation or the need to add
@RequestParam (defaultvalue= ") Long pageSize
If the name of the parameter is the same as the one passed by it, it can be simply encapsulated, without the need for this annotation
if it is different, it will use this annotation, which has the value property, can accept the argument and give the custom parameter
DefaultValue is to give the default worth
@RequestBody If the requested parameter is JSON data, this annotation can turn the JSON data into Pojo .
parameters can also be passed a Model Model Object
can pass a value to the page via Model.addattribute ("item", item)
you can also pass HttpRequest and httpresponse two objects
Project Summary SPRINGMVC Related