spring form data 乱码解决办法 和 显示乱码解决办法

类别:Java 点击:0 评论:0 推荐:
在web.xml里面添加
<filter>
<filter-name>SetCharacterEncoding</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>SetCharacterEncoding</filter-name>
<url-pattern>*.htm</url-pattern>
</filter-mapping>

<!-- 要过滤目录 -->
<filter-mapping>
<filter-name>SetCharacterEncoding</filter-name>
<url-pattern>*.htm</url-pattern>
</filter-mapping>



显示乱码:
在你的*-servlet.xml 里面定义

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property>
    <property name="prefix"><value>/WEB-INF/jsp/</value></property>
    <property name="suffix"><value>.jsp</value></property>
    <!--修改的地方-->
    <property name="contentType">
        <value>text/html;charset=UTF-8</value>
    </property>
</bean>

本文地址:http://com.8s8s.com/it/it12330.htm