SPRINGMVC Learning---basic knowledge assessment

Source: Internet
Author: User


Springmvc

1, Springmvc's work flow

Process:

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 POST request Chinese garbled problem, get how to deal with it?

Join:<filter> <filter-name>CharacterEncodingFilter</filter-name> <filter-class> in Web. xml Org.springframework.web.filter.characterencodingfilter</filter-class> <init-param> <param-name&gt ;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> above can solve the POST request garbled problem. For GET request Chinese parameter garbled solution There are two: Modify the Tomcat configuration file to add code consistent with the project code, as follows: <connectoruriencoding= "Utf-8" connectiontimeout= "20000" port= "8080" protocol= "http/1.1" redirectport= "8443"/> Another way to Recode 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

What is the main difference between 3.SpringMVC and Struts2?

The entrance to the ①SPRINGMVC is a servlet, the front-end controller, and the STRUTS2 entry is a filter filter.

②springmvc is based on method development, the transfer parameters are through the method parameter, can be designed as a single case or multiple examples (recommended single case), Struts2 is based on class development, passing parameters are through the properties of the class, can only be designed as a number of examples.
③struts uses the value stack to store the request and the response data, through the OGNL access data, SPRINGMVC through the parameter parser is to parse the request object content into a method parameter, the response data and the page is encapsulated into a Modelandview object, Finally, the model data is transferred to the page through the request object. The JSP view parser uses Jstl by default.

4. Talk about the comparative advantages of SPRINGMVC and STRUTS1,STRUTS2

Performance on STRUTS1>SPRINGMVC>STRUTS2 development speed SPRINGMVC and Struts2 almost, higher than Struts1


5. What is the core entrance class of SPRINGMVC, and what is the difference between struts1,struts2?

SPRINGMVC is Dispatchservlet,struts1, Actionservlet,struts2 is strutsprepareandexecutefilter.


6. SPRINGMVC Controller is not a singleton mode, if yes, what is the problem, how to solve

is a singleton mode, so in multi-threaded access when the thread security issues, do not use synchronization, will affect performance, the solution is in the controller can not write segments


7. Annotations for controllers in Spingmvc generally with that, there are no other annotations to replace

The general use @conntroller annotation, expresses is the expression layer, cannot use other annotations instead.


8. What does @RequestMapping annotation do with a class?

On a class, the method that represents all response requests in a class is the parent path of the address.


9. How to map a request to a specific method

Add the annotation @requestmapping directly to the method and write the path to intercept in this note


10. If in the interception request, I want to intercept the method of Get mode submission, how to configure

You can add method=requestmethod.get to the @requestmapping annotations.


11. If in the interception request, I want to intercept the submission parameter contains the "Type=test" string, How to configure

You can add params= "Type=test" to the @requestmapping annotations.


12. I want to get the parameters passed from the foreground in the interception method, how to get

Declare this parameter directly in the formal parameter, but it must be the same name as the passed argument.


13. If the foreground has a number of parameters passed in, and these parameters are an object, then how to quickly get this object

Declaring the object directly in the method, SPRINGMVC automatically assigns the attribute to the object.


14. How to get request in the method, or session

Declaring the REQUEST,SPRINGMVC directly in the parameter of the method automatically passes in the Request object


What is the return value of the function in Springmvc.

The return value can have a number of types, string, Modelandview, and is generally better than string


Springmvc How to handle the return value

Springmvc the full return value with prefix + return value + suffix based on the prefix and suffix of internalresourceviewresolver in the configuration file


Springmvc how to set redirection and forwarding

Adding "forward:" Before the return value allows the result to be forwarded, such as "FORWARD:USER.DO?NAME=METHOD4" with the return value preceded by "redirect:" To redirect the return value, such as "redirect:http://www.baidu.com"


Springmvc. What objects are used to pass data from the background to the foreground

Through the Modelmap object, you can put the object inside the object with the Put method, the foreground can be obtained by El Expression


There is a class in SPRINGMVC that combines views and data together, what's called

Call Modelandview.


20. How to put the data inside the Modelmap into the session

You can add a @sessionattributes annotation to a class that contains a string that is the key to be placed inside the session


How SPRINGMVC and Ajax call each other.

The Jackson framework allows you to translate the objects in Java directly into a JSON object that JS can recognize.
The steps are as follows
1. Join Jackson.jar
2. Configure the mapping of JSON in the configuration file
3. In the accepted Ajax method can return directly to Object,list, but the method is preceded by a @responsebody annotation


22. What to do when a method returns special objects to Ajax, such as object,list, etc.

To add @responsebody annotations


SPRINGMVC, what did the Interceptor say?

  There are two ways to do this, one is to implement the interface, the other is to inherit the adapter class, and then configure the interceptor in the SPRINGMVC configuration file:  <!--Configure the SPRINGMVC interceptor--><mvc:interceptors>    <!--Configure an interceptor bean to intercept all requests by default--    <bean id= "Myinterceptor" class= " Com.et.action.MyHandlerInterceptor "></bean>     <!--block only for partial requests--    <mvc:interceptor>       <mvc:mapping path= "/modelmap.do"/>       <bean class= "Com.et.action.MyHandlerInterceptorAdapter"/ >    </mvc:interceptor></mvc:interceptors>


24. Talk about the implementation process of SPRINGMVC

When the system starts, it creates a spring container based on the configuration file, first sending the HTTP request to the core controller dispatherservlet,spring container through the mapper to find the business controller,
Use the adapter to find the appropriate business class, in the business class when the data encapsulation, before encapsulation may involve type conversion, after executing the business class using Modelandview for view forwarding, data in the model, the map to pass the data for the page display.

"More References"http://www.cnblogs.com/huajiezh/p/6415388.html

SPRINGMVC Learning---basic knowledge assessment

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.