spring MVC-related interview questions

Talk about your understanding of the Spring MVC?

Spring MVC is a Java-based implementation of the request for driving the MVC design pattern type lightweight Web framework, the web layer functions to decouple the Model, View, Controller separation, the complex web application divided into several logic clear part, to simplify development, reduce error, the fit between the easy to develop group.

How spring mvc set Redirects and Forwards?

Forwarding: In the return values ​​preceded by "forward:", such as "forward:? User.do name = method4"

Redirection: return value preceded by "redirect:", such as "redirect: http: //www.baidu.com"

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

(1) post requests to solve the garbage problem:

A filter disposed in web.xml CharacterEncodingFilter, arranged utf-8;

<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 solution appears there are two:

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

SpringMVC commonly used annotation what?

@RequestMapping: url mapping for processing a request for comments, and can be used for class or method. For the class, in response to the request by any methods that are based on the class as a parent of the path address.

@RequestBody: annotation data received http request json implemented will convert json java object.

@ResponseBody: Notes achieve conreoller method returns the object into json response to customer objects.

 

Guess you like

Origin www.cnblogs.com/ldddd/p/11224138.html