Spring surface examination questions

Original link: https://my.oschina.net/u/1186503/blog/1632947

1. What is Spring Framework? What are the main module Spring framework?

Spring is a framework providing for the comprehensive development of Java applications, broad-based support for the Java platform.

Spring to help developers solve the problem of the development of fundamental, so that developers can focus on application development.

Spring framework itself is also a well-built according to the design mode, which makes the integration of the Spring framework we can feel at ease in a development environment, do not worry about how Spring work in the background.

Spring Framework has been integrated in more than 20 modules. These modules are divided as shown in FIG main core container, data access / integration ,, Web, AOP (Aspect Oriented Programming), tools, modules and test message.

1. Simple talk about SpringMVC workflow?

8f046235-4658-4bb2-8569-a45eed6cee73

流程 
1、用户发送请求至前端控制器DispatcherServlet 
2、DispatcherServlet收到请求调用HandlerMapping处理器映射器。 
3、处理器映射器找到具体的处理器,生成处理器对象及处理器拦截器(如果有则生成)一并返回给DispatcherServlet。 
4、DispatcherServlet调用HandlerAdapter处理器适配器 
5、HandlerAdapter经过适配调用具体的处理器(Controller,也叫后端控制器)。 
6、Controller执行完成返回ModelAndView 
7、HandlerAdapter将controller执行结果ModelAndView返回给DispatcherServlet 
8、DispatcherServlet将ModelAndView传给ViewReslover视图解析器 
9、ViewReslover解析后返回具体View 
10、DispatcherServlet根据View进行渲染视图(即将模型数据填充至视图中)。 
11、DispatcherServlet响应用户

2.如何解决POST请求中文乱码问题,GET的又如何处理呢?

在web.xml中加入:

 

  1. <filter>
  2.     <filter-name>CharacterEncodingFilter</filter-name>
  3.     <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  4.     <init-param>
  5.         <param-name>encoding</param-name>
  6.         <param-value>utf-8</param-value>
  7.     </init-param>
  8. </filter>
  9. <filter-mapping>
  10.     <filter-name>CharacterEncodingFilter</filter-name>
  11.     <url-pattern>/*</url-pattern>
  12. </filter-mapping>

以上可以解决post请求乱码问题。对于get请求中文参数出现乱码解决方法有两个:

修改tomcat配置文件添加编码与工程编码一致,如下:

 

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

 

 另外一种方法对参数进行重新编码:

 

  1. 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

3.SpringMVC with Struts2 main difference?

①springmvc inlet is a front controller servlet i.e., a filter inlet and struts2 worrying too much.

②springmvc method is based on the development parameters are passed by the process parameter, can be designed as a single or multiple Example Example (recommended singleton), Struts2 is class-based development, the parameters passed by the attribute class, only cases of design. 
③Struts using data values stored in the stack and in response to the request, the request is SpringMVC by OGNL target content access data, the parameter parser as a method parameter, and the page response data encapsulated into ModelAndView object model data in turn by the last the request object is transferred to the page. Jsp view parser jstl default.

Reproduced in: https: //my.oschina.net/u/1186503/blog/1632947

Guess you like

Origin blog.csdn.net/choy9999/article/details/100591123