目前急需解决:      项目中使用的是struts2  编码环境是GBK
      我在做跳转的时候使用 <result name="del_userInRole" type="redirect">role/role!roleDetail.action?roleid=${roleid}&amp;crmUser.code=${crmUser.code}&amp;crmUser.name=${crmUser.name}&amp;page=${page}</result>
       传过去后发现crmUser.name 显示到页面是乱码 浏览器的地址栏中crmUser.name也是乱码
       整个项目的编码环境都是GBK struts的配置文件已经加了<constant name="struts.i18n.encoding" value="GBK"/>
tomcat的server.xml也设置了GBK编码, 为什么还是乱码呢? 该怎么解决??   请各位高手帮帮忙哦~

解决方案 »

  1.   

    Action中String temp = new String(crmUser.name.getBytes("ISO-8859-1"), "GBK");
      

  2.   

    先看看你的程序中filter那里是否做过转码,
    要是没有估计是与页面交互出现的乱码,
    可以通过设置response.setCoding,request.setCoding,jsp中头部的metadata也设置好,
    应该没有问题
      

  3.   

      用spring的过滤器 在web.xml
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
      <!-- spring 过滤器 -->
      <filter>
           <filter-name>CharsetFilter</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>CharsetFilter</filter-name>
       <url-pattern>/*</url-pattern>
      </filter-mapping>
      <!-- struts 过滤器 -->
      <filter>
    <filter-name>struts2</filter-name>
    <filter-class>
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    </filter-class>
    </filter>
    <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>*.do</url-pattern>
    </filter-mapping>

    或者<%request.setCharacterEncoding("GBK") 
      

  4.   

    web.xml里面经写了过滤器,并且页面使用velocity实现 velocity的配置文件velocity.properties也定义了编码格式input.encoding=GBK output.encoding=GBK  但还是不行啊~~~~!!
      

  5.   

    请求方式不对吧,还有一个是struts2的拦截器好像不是很好使,你看看你的请求方式是不是post
      

  6.   

    顺便也提个问题  <result name="del_userInRole" type="redirect">role/role!roleDetail.action?roleid=${roleid}&amp;crmUser.code=${crmUser.code}&amp;crmUser.name=${crmUser.name}&amp;page=${page}</result>
        在struts 注解里面如何实现这种动态传参的效果?????
       请大家帮帮忙