2019 springmvc high-frequency interview questions (java)

Foreword

2019 will soon be over, with us is about to usher in the new year, the Spring Festival, once again usher in a new interview gold and three silver four seasons. Then, as the program you apes, really be prepared for it, also, or content with their jobs, continue to do the things at hand.

Of course, no matter how you choose, if you're really ready to quit after gold and three silver four, then as a Java engineer, may not be read. How in a few months time, rapid adequately prepare it for the upcoming interview?

1. What is Spring MVC? A brief introduction of your understanding of springMVC?

Spring MVC is a framework to simplify application development framework for web application development, it is a module of Spring, without an intermediate layer of integration to integrate, and it belongs to the same Struts2 presentation layer based on MVC architecture. Model in the web, the MVC is a popular frame, by the Model, View, Controller separation, the more complex web application divided into several portions and logically, to simplify development, reduce error, between the group of developers who facilitate the cooperation.

2, SpringMVC process?

1, the user sends a request to the front end of the controller the DispatcherServlet;
2, the DispatcherServlet After receiving the request, the call processor HandlerMapping mapper request to obtain the Handle;
. 3, the processor finds a specific mapping processor according to the request url, objects, and generation processor processor blocker (if any is generated) collectively returned to the DispatcherServlet;
. 4, the DispatcherServlet call processor through the processor HandlerAdapter adapter;
5, execution processor (Handler, also called back-end);
. 6, returned to complete execution Handler ModelAndView;
. 7, the Handler HandlerAdapter is returned to the execution result ModelAndView the DispatcherServlet;
. 8, the DispatcherServlet ModelAndView pass the parser parses ViewResolver view;
9, returns the specific ViewResolver view parsed;
10, the DispatcherServlet render view of view (filling about to model data to view)
. 11, the DispatcherServlet user response.

3, Spring mvc advantages

1, which is based on COM technology. All application objects, both controllers and views, or the business objects and the like are java components. And tight integration and other infrastructure Spring provides.
2, does not depend on Servlet API (although the goal is so, but in reality time is really dependent on the Servlet)
3, can use any variety of view technologies, not just JSP
4, supports a variety of resource mapping request strategy.
5, it should be easy to extend.

4, Spring MVC's major components?

1, DispatcherServlet front-end controller (not require programmers)
action: receiving a request, in response to a result equivalent to the transponder, with DispatcherServlet reduces the coupling between the other components.
2, processor mapper HandlerMapping (does not require programmers to develop)
Role: According to the URL request to find Handler
3, the processor adapter HandlerAdapter
Note: To follow the rules HandlerAdapter required to write at the time of writing Handler, so that the adapter can HandlerAdapter the right to perform Handler.
4, the processor Handler (require programmers)
5 viewresolver ViewResolver (not require programmers)
action: parsing a logical view of a view into real name resolution view (View)
. 6, View View (the programmer need development JSP)
view is an interface, the implementation of which support different types of views (jsp, freemarker, pdf, etc.)

5, the difference SpringMVC and struts2 What?

1, springmvc i.e. inlet is a front controller servlet (DispatchServlet), and a filter inlet struts2 filter (StrutsPrepareAndExecuteFilter).
2, springmvc method is based on the development of (a method corresponding to a url), parameters passed to the method of the request parameters, can be designed as a single embodiment or embodiments (recommended singleton), Struts2 is class-based development, the parameters passed by the class properties can only be designed to be more cases.
3, Struts using the data value stack memory requests and responses through OGNL access data, the parser is a parameter SpringMVC REQUEST request content analysis, and a parameter assignment method, and views into the data package ModelAndView object, and finally turn ModelAndView model data is transferred to the page through the reques domain. Jsp view parser jstl default.

6, SpringMVC how to set redirection and forwarding?

(1) in the return value preceded by "forward:" you can make forward the results, such as "Forward: user.do method4 name =?"
(2) in the return value preceded by "redirect:" you can make the return value redirection, such as "redirect: http: //www.baidu.com"

7, SpringMVC how AJAX and call each other?

Jackson by the frame can be put inside the Java object directly into Json Js identifiable objects. Specific steps are as follows:
(1) was added Jackson.jar
(2) arranged json mapping in the configuration file
(3) Ajax receiving method which can directly return Object, List, etc., but the front @ResponseBody To add annotations.

8, SpringMVC inside the interceptor is how to write?

There are two ways for writing, one is to achieve HandlerInterceptor interface adapter class inherits another interface method among ,, Next, processing logic is implemented; interceptors can then configure the SpringMvc profile.

9, how to solve the problem of Chinese garbled POST request, GET is how to deal with it?

1, to solve the garbage problem post a request:
join in 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>

2, get the request parameters Chinese garbled There are two solutions:
① modify tomcat configuration file to add the same coding and engineering codes, as follows:

<ConnectorURIEncoding="utf-8" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>

② Another method of re-encoding parameters:

String userName = new String(request.getParamter("userName").getBytes("ISO8859-1"),"utf-8")

ISO8859-1 is tomcat default encoding, content needs to be encoded by the tomcat utf-8 encoding.

10, Spring MVC exception handling?

A: You can throw an exception Spring framework, it is handled by the Spring framework; we only need to configure a simple exception handler, add the page to view the exception handler.

11, SpringMvc controller is not a singleton, and if so, what is the problem, how to solve?

A: Yes, a singleton, so when in multithreaded access have thread-safety issues, do not use synchronization, will affect the performance of the solution is not written in a field controllers inside.

12, notes the controller SpingMvc which is generally used, there is no other alternative to comment?

A: Generally used @Conntroller annotation indicating that the presentation layer, can not be replaced with other comments.

13, @RequestMapping notes used in the class above what effect?

A: is used to process a request for comments address mapping, it can be used for class or method. For the class, all the methods in response to the request class are represented in the address as the parent path.

14, how to map a request to a specific method of the above?

A: Direct annotate @RequestMapping in the method above, and write on the path to be intercepted in the notes inside.

15, if the intercept request, I would like to get intercepting method of submission, how to configure?

A: You can add notes inside ethod = RequestMethod.GET in @RequestMapping.

16, how to get inside the method Request, or Session?

A: The statement request directly in the parameter method, SpringMvc automatically passed to the request object.

17, from the front desk if you want to get the parameters passed in a method to intercept it, how to get?

A: Direct declare this parameter in parameter inside it, but the name and parameters must pass over the same.

18, the front desk if there are a number of parameters passed, and these are the parameters of an object, then how to quickly get this object?

A: Direct declare this object in a method, SpringMvc property will automatically assign to this object inside.

19, SpringMvc the return value of the function what is?

A: The return value can have many types, there String, ModelAndView, but generally use String better.

20, SpringMvc what the object from the front desk to pass data back?

A: By ModelMap object, you can use the put method, in which the object is added to the object inside, the front desk you can get by el expressions.

21, SpringMvc There is a category to view and data are merged together, what is?

A: The name is ModelAndView.

22, how to put data into the Session ModelMap inside there?

A: You can add @SessionAttributes annotation, which contains the string is to be placed inside the session key in a class above.

23, when a method returns a special object to AJAX, such as Object, List, etc., deal with what needs to be done?

A: To add @ResponseBody comment.

Public concern ape Society program number , reply the keyword " interview " to get face questions zk, dubbo, springboot, springcloud, mybatils, apollo and other technologies.

 

No public: program ape Society

Real-time updates weekly

Guess you like

Origin www.cnblogs.com/myworked/p/12122862.html