你扩展一下ActionServlet好了.
代码如下:
public class MainServlet extends ActionServlet {    protected static final String DEFAULT_CHARSET = "GBK";
   
    public void doGet(HttpServletRequest request,
              HttpServletResponse response)
        throws IOException, ServletException {
        request.setCharacterEncoding(DEFAULT_CHARSET);
        process(request, response);
    }    public void doPost(HttpServletRequest request,
               HttpServletResponse response)
        throws IOException, ServletException {
        request.setCharacterEncoding(DEFAULT_CHARSET);
        process(request, response);
    }
}
在Web.xml中参数配置同ActionServlet
这样,在页面输入中文就不用再转码了

解决方案 »

  1.   

    我利用的Struts结构,现在是在JSP直接激发Action完成处理,没有用到ActionServlet.在此架构中如何运用?讲具体一点好吗?
    非常谢谢!
      

  2.   

    不是很明白你的意思。
    Up一下吧 将“流氓无赖”测试到底
    ——始于2003年7月
    树欲止而风不停,行云流水匆匆去;
    树梢蚂蚱凭空望,江边浪花碎巨石; 支持“流金岁月”!!!
    ——2003年12月24日am^@^
      

  3.   

    就是我在JSP前台录入的中文,经过ACtion重定向后,全部变成乱码?
      

  4.   

    用编码filter就可以解决问题了.
      

  5.   

    用编码filter就可以解决问题了.
    宠物店的源码中有现成的
      

  6.   

    如何支持中文
    关于Struts支持中文的问题,大多都是写个过滤器在doFilter函数里设置字符集
        package com.web;
    import javax.servlet.*;
    import java.io.IOException;
    public class EncodeFilter implements Filter {
    protected String encoding = null;
    protected FilterConfig filterConfig = null;
    protected boolean ignore = true;
    public void destroy() {
        this.encoding = null;
        this.filterConfig = null;
    }
    public void doFilter(ServletRequest request, ServletResponse response,
                          FilterChain chain)
    throws IOException, ServletException {
       if (ignore || (request.getCharacterEncoding() == null)) {
         String encoding = selectEncoding(request);
         if (encoding != null)
           request.setCharacterEncoding(encoding);
       }
       chain.doFilter(request, response);
    }
    public void init(FilterConfig filterConfig) throws ServletException {
        this.filterConfig = filterConfig;
        this.encoding = filterConfig.getInitParameter("encoding");
        String value = filterConfig.getInitParameter("ignore");
        if (value == null)
          this.ignore = true;
        else if (value.equalsIgnoreCase("true"))
          this.ignore = true;
        else if (value.equalsIgnoreCase("yes"))
          this.ignore = true;
        else
          this.ignore = false;
    }
    }
    然后,在web.xml文件配置一个过滤器,给出encoding和ignore设置过滤*.do就可以了,如下:
    <filter>
    <filter-name>Set Character Encoding</filter-name>
    <filter-class>com.web. EncodeFilter </filter-class>
    <init-param>
    <param-name>encoding</param-name>
    <param-value>GB2312</param-value>
    </init-param>
    <init-param>
    <param-name>ignore</param-name>
    <param-value>true</param-value>
    </init-param>
    </filter>
    <!-- Filter Mapping -->
    <filter-mapping>
    <filter-name>Set Character Encoding</filter-name>
    <url-pattern>*.do</url-pattern>
    </filter-mapping>
      

  7.   

    需要加一个filter,并且将jsp页的 charset全部改为utf-8
    其他的I18N的支持,就不用管太多了,直接使用它的message就可以了。
      

  8.   

    to  Gene2000():String encoding = selectEncoding(request);
    这是什么呀,编译出错