jsp向action提交数据时出现乱码的解决办法:
在web.xml中,添加filter
//***************************************
<!-- 注:filter1开始 -->
<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>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 注:filter1结束 -->
<!-- 注:filter2开始 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
<init-param>
<param-name>actionPackages</param-name>
<param-value>com.tongcard.demo.web.actions</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 注:filter2结束 -->
//*******************************************
注意两个filter顺序不能颠倒!
本文介绍了解决JSP向action提交数据时出现乱码的方法,在web.xml中配置CharacterEncodingFilter过滤器,并设置字符编码为UTF-8,确保所有请求都被此过滤器处理。
337

被折叠的 条评论
为什么被折叠?



