The new project is ready to discard the JSP instead of HTML, encountered a number of strange problems, now recorded as follows:
First, the view resolution problem, return to the view time in the controller is unusually slow, a page of nearly 20 seconds, the method is executed quickly, that is, the last return ViewName has been stuck, a variety of checks no problem, and finally to see the view resolution configuration:
<--org.springframework.web.servlet.view.internalresourceviewresolver-->
<Beanclass= "Org.springframework.web.servlet.view.InternalResourceViewResolver"> < Propertyname= "prefix"value= "${web.view.prefix}"/> < Propertyname= "suffix"value= "${web.view.suffix}"/> < Propertyname= "ContentType"> <value>text/html; Charset=utf-8</value> </ Property> </Bean>
Org.springframework.web.servlet.view.InternalResourceViewResolver is the parser used in JSP, the HTML should use the Freemaker view diagram to analyze
<!--Define view file parsing HTML private - <BeanID= "Freemarkerconfig"class= "Org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> < Propertyname= "Templateloaderpath"> <value>${web.view.prefix}</value> </ Property> </Bean> <BeanID= "Htmlviewresolver"class= "Org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"> < Propertyname= "suffix"value= ". html" /> < Propertyname= "Order"value= "0"></ Property> < Propertyname= "ContentType"value= "Text/html;charset=utf-8"></ Property> </Bean>
After the change, sure enough speed in the fly, fix. But the page Chinese is garbled, this trivial one, the Web application we solve garbled is a master, began the following tour:
1. Change HTML page First: invalid
< Head > < title > login </title> <http-equiv = "Content-type" content = "text/html; charset=utf-8" >
2.web.xml:
<Filter> <Filter-name>Encodingfilter</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> <Init-param> <Param-name>Forceencoding</Param-name> <Param-value>True</Param-value> </Init-param> </Filter> <filter-mapping> <Filter-name>Encodingfilter</Filter-name> <Url-pattern>/*</Url-pattern> </filter-mapping>
Invalid, even sick Touyi, change forceencoding to False try
3:controller Code: (online looking for various methods)
@RequestMapping (value = "${adminpath}/login",produces = "Text/html;charset=utf-8", method =requestmethod.get)//@ResponseBody PublicString Login (httpservletrequest request, httpservletresponse response, String s) {Try{ request.setcharacterencoding ( "UTF-8"); } Catch(unsupportedencodingexception e) {e.printstacktrace (); } Response.setcontenttype ( "Text/html;charset=utf-8"); HttpServletRequest hrequest= Webutils.tohttp (request);
4:tomcat server Serer.xml,uriencoding=utf-8, this to get request Chinese parameter actually works.
。。。。。
Eventually it was not able to solve, almost gave up. Baidu on the internet all kinds of "Springmvc HTML Chinese garbled", and finally think, is not freemaker view parser problem, change the keyword "springmvc freemaker view parsing Chinese garbled", sure enough there is a new method, as follows
<!--Define view file parsing HTML private - <BeanID= "Freemarkerconfig"class= "Org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> < Propertyname= "Templateloaderpath"> <value>${web.view.prefix}</value> </ Property> < Propertyname= "Freemarkersettings"> <Props> <propKey= "Template_update_delay">1</prop> <prop key= "default_encoding" >UTF-8</prop>//Key solution points <propKey= "Number_format">0.##</prop> <propKey= "Datetime_format">YYYY-MM-DD HH:mm:ss</prop> </Props> </ Property> </Bean> <BeanID= "Htmlviewresolver"class= "Org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"> < Propertyname= "suffix"value= ". html" /> < Propertyname= "Order"value= "0"></ Property> < Propertyname= "ContentType"value= "Text/html;charset=utf-8"></ Property> </Bean>
Finally solved, Chinese garbled real headache ah .... , which day programming language written in Chinese, it will be completely solved! Baidu used for so many years, you really will?
Springmvc HTML view parsing and Chinese garbled problem