使用struts2的等标签向action传值出现中文乱码的解决方法

时间:2021-12-27 13:05:08

         最近公司OA改版,由于修改了原来的框架,所以很多东西都得重新实现。

         废话不多说,问题所在:在一个页面中使用超链接,如下

<s:url id="resultDetailURL" action="queryPrice_detail">
               <s:param name="pageindex" value="pageindex"></s:param>
               <s:param name="model.id" value="%{id}"></s:param>               
               <s:param name="nameOrAddress" value="%{nameOrAddress}"></s:param>
               <s:param name="city" value="%{city}"></s:param>
               <s:param name="fwjg" value="%{fwjg}"></s:param>
               <s:param name="fwcx" value="%{fwcx}"></s:param>
               <s:param name="fwlx" value="%{fwlx}"></s:param>
               <s:param name="startPrice" value="%{startPrice}"></s:param>
               <s:param name="endPrice" value="%{endPrice}"></s:param>
                </s:url>
              <s:a href="%{resultDetailURL}" title="详细信息"><img src="images/oprator/view_detail.png" style="margin-bottom:-2px" border="0" title="详细信息" alt="详细信息" />&nbsp;详细信息&nbsp;</s:a>    

 

       向action中传值时出现中文乱码,页面的编码方式已经设置为 UTF-8形式:


<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>    

     

        纠结了挺久,最后发现原来是在tomcat的server.xml配置文件中使用了GBK的编码方式:

            <Connector port="8085" protocol="HTTP/1.1"
                         maxTreads="500"
                         minSpareThreads="10" 
                         maxSpareThreads="50"
                        acceptCount="50"
                        connectionTimeout="20000"
                        redirectPort="8443"
                        URIEncoding="GBK"/>

           将GBK改为UTF-8,问题解决,当然情况不同可能出错点也不一样,仅供参考。