Springmvc Interview Summary _ Face test

Source: Internet
Author: User
1. Simply talk about the SPRINGMVC workflow
Process
1. User send request to Front controller Dispatcherservlet
2. Dispatcherservlet received a request to invoke the Handlermapping processor mapper.
3. The processor mapper finds a specific processor, generates the processor object and the processor interceptor (if any is generated) and returns it to the Dispatcherservlet.
4. Dispatcherservlet Call Handleradapter Processor Adapter
5. The Handleradapter is adapted to call the specific processor (Controller, also known as the back-end controller).
6. Controller execution Complete return Modelandview
7. Handleradapter will return controller execution results modelandview to Dispatcherservlet
8. Dispatcherservlet passes Modelandview to Viewreslover view parser
9. Return to specific view after Viewreslover resolution
Dispatcherservlet renders a view based on view (the model data is populated into the view).
Dispatcherservlet Response User
2. How to solve the POST request Chinese garbled problem, get and how to deal with it? Add a coded filter 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 solutions for get requests for Chinese parameters:
Modifying the Tomcat configuration file add code is consistent with the engineering code, as follows:
<connectoruriencoding= "Utf-8" connectiontimeout= "20000" port= "8080" protocol= "http/1.1" redirectport= "8443"/ >
Another method is to encode the parameters again:
String userName = new String (Request.getparamter ("UserName"). GetBytes ("Iso8859-1"), "Utf-8"
Iso8859-1 is the Tomcat default encoding, which requires that the tomcat-encoded content be encoded in Utf-8 3. The main difference between SPRINGMVC and Struts2 ①springmvc's entrance is a servlet, the front-end controller, and the Struts2 Inlet is a filter filter.
②SPRINGMVC is based on the method of development, passing parameters are through the method parameter, can be designed as a single case or multiple cases (recommended single case), Struts2 is based on class development, passing parameters are through the properties of the class, can only be designed as many examples.
③struts uses the value stack to store the request and the response data, through the OGNL Access data, SPRINGMVC the Request object content to parse into the method parameter by the parameter parser, the response data and the page are encapsulated into the 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 advantages of the comparison between Springmvc and struts1,struts2 on the struts1>springmvc>struts2 development speed SPRINGMVC and STRUTS2, higher than the STRUTS1
5. What is the core entry class of the SPRINGMVC, what is the struts1,struts2 of the SPRINGMVC is Dispatchservlet,struts1 is Actionservlet, Struts2 is strutsprepareandexecutefilter.

6. SPRINGMVC controller is not a single case mode, if it is, what is the problem, how to solve is a single case mode, so in multi-threaded access to the thread security problems, do not use synchronization, will affect performance, the solution is in the controller can not write section
7. Spingmvc of the controller in the general use of that, there is no other annotation can replace the general use of @conntroller annotation, said is the performance layer, can not use other annotations instead.
8. @RequestMapping annotations are used on the class for the purposes of the class, and all the response requests in the class are represented by the address as the parent path.
9. How to map a request to a specific method above directly on the method plus annotation @requestmapping, and in this note write the path to intercept
10. If in the interception request, I want to intercept the get way submission method, how configures may add in the @requestmapping annotation inside method=requestmethod.get
11. If in the interception request, I want to intercept the Submit parameter contains "Type=test" string, how to configure can add params= "Type=test" 12 in the @requestmapping annotation. I want to get the parameters that come in from the foreground in the Intercept method, and how to get a declaration of this parameter directly in the parameters, but it must have the same name as the passing parameters.
13. If the front desk has many parameters to pass in, and these parameters are an object, how to quickly get the object to declare the object directly in the method, SPRINGMVC will automatically assign the attribute to this object
14. How to get request in the method, or the session directly in the method of the formal parameter declaration REQUEST,SPRINGMVC automatically put the request object into
What is the return value of a function in SPRINGMVC the return value can have many types, there are string, Modelandview, when the general string is better
Springmvc How to handle the return value SPRINGMVC based on the prefix and suffix of internalresourceviewresolver in the configuration file, the complete return value is composed of the prefix + return value + suffix
Springmvc how to set redirects and forwards the return value preceded by "Forward:" allows the result to be forwarded, such as "FORWARD:USER.DO?NAME=METHOD4" in front of the return value Plus "redirect:" To redirect the return value , such as "redirect:http://www.baidu.com"
Springmvc with what object from the background to pass data to the foreground through the Modelmap object, you can use put method in this object, add the object to the inside, the foreground can be through El expression to get
In Springmvc, there is a class that combines views and data together, called What Modelandview
20. How to put the modelmap inside the data into the session can be added to the class above @sessionattributes annotation, which contains the string is to put the key in the session
How SPRINGMVC and Ajax call each other through the Jackson framework can translate the objects in Java directly into the JSON can be recognized by the object. The specific steps are as follows
1. Join Jackson.jar
2. Configure the JSON mapping in the configuration file
3. In the acceptance of Ajax methods can be directly returned to Object,list, and so on, but the method before adding @responsebody annotation
22. When a method returns a special object to Ajax, such as object,list, what needs to be done plus @responsebody annotations
Springmvc How the Interceptor was written.
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 SPRINGMVC Interceptor-->
<mvc:interceptors >
    <!--Configure an interceptor bean to have the default is to intercept all requests-->
    <bean id= "Myinterceptor" class= " Com.et.action.MyHandlerInterceptor "></bean>

    <!--only intercept for partial requests-->
    <mvc:interceptor>
       <mvc:mapping path= "/modelmap.do"/>
       <bean class= "Com.et.action.MyHandlerInterceptorAdapter"/ >
    </mvc:interceptor>
</mvc:interceptors>
24. How to implement a number of management controllers in the class using @scope ("prototype")

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.