解决乱码

eclipse 设置默认编码为Utf-8,需要设置的几处地方为:

 Window->Preferences->General ->Content Type->Text->JSP 最下面设置为UTF-8

 Window->Preferences->General->Workspace   面板Text file encoding 选择UTF-8

 Window->Preferences->Web->JSP Files 面板选择 ISO 10646/Unicode(UTF-8)

tomcat服务器/conf目录/server.xml文件

将相关语句改为:

<Connector port="8008" protocol="HTTP/1.1" connectionTimeout="20000"   redirectPort="8443"  URIEncoding="UTF-8"/>

SpringMvc中web.xml中配置过滤器

<!-- 配置请求过滤器,编码格式设为UTF-8,避免中文乱码--> 
    <filter> 
       <filter-name>springUtf8Encoding</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>springUtf8Encoding</filter-name> 
       <url-pattern>/*</url-pattern> 
   </filter-mapping> 

这里,不在介绍数据库乱码了!!!

猜你喜欢

转载自blog.csdn.net/riju4713/article/details/81304524