action代码:
public class TestAction extends ActionSupport{

private String name; 
@Override
public String execute() throws Exception {
System.out.println(name);
return "success";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
struts.xml代码:
 <action name="test" class="com.yna.action.TestAction"> 
             <result>index.jsp</result> 
  </action>
web.xml代码:
        <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>/*</url-pattern>  
        </filter-mapping> 访问时http://localhost:8080/html5/test?name=中     execute方法里面的输出为乱码。(编码格式均为utf-8)

解决方案 »

  1.   

    像你这种方式提交的请求,要在后台转下编码。name=new String("ISO-8859-1","UTF-8")如果表单提交的话一般不会出现乱码(编码一致的话)
      

  2.   

    你项目没有转码机制吗?  filter 拦截下、转码在放行、还有服务器的编码集过滤设置你对应的utf-8提交表单的话  用post方式(如果post乱码就证明你没有设置filter拦截器、拦截所有请求并且转码之后在放行、、相对应的  get方式乱码 请设置tomcat的编码集、具体都请百度之)
      

  3.   

    我只是想练下struts hibernate,所以没有用filter,提交表单时用的post。struts 2.1.6有乱码bug,我用的struts2.3.4.1,我以为不会出乱码的。
    非常谢谢你的回答。
      

  4.   

    1。filter设置编码
    2。strtus.i18n.encoding设置编码,每次都设置一致