基于struts1.2架构的
jsp代码如下:JSp头信息:<%@ page contentType="text/html;charset=gb2312" import="java.util.*" pageEncoding="gb2312" language="java"%>
<%@ page import="connect.*,java.sql.*,com.wanzo.saasBean.*"%>action代码如下:public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
request.setCharacterEncoding("gb2312");
response.setContentType("text/html;charset=gb2312");
web.xml过滤器:<filter>
    <filter-name>encoding</filter-name>
    <filter-class>com.wanzo.util.Encoding</filter-class>  <!--这里写你编码类在的位置-->
    <init-param>
      <param-name>encoding</param-name>
      <param-value>gb2312</param-value>
    </init-param>
  </filter>
  <filter-mapping>
     <filter-name>encoding</filter-name>
     <url-pattern>/*</url-pattern>
  </filter-mapping>
现在出现了乱码这个很讨厌的问题 把字符集改为gbk,utf-8都不可以 tomcat 字符集utf-8
希望各位援手!!!!!小弟不胜感谢 

解决方案 »

  1.   

    过滤器:
    package com.wanzo.util;import java.io.IOException;import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;public class Encoding implements Filter {
       
       private FilterConfig config=null;
       String encoding=null;
     public void destroy() {
      this.encoding=null;
      this.config=null; } public void doFilter(ServletRequest request, ServletResponse response,
       FilterChain chain) throws IOException, ServletException {
         if(encoding!=null)
          request.setCharacterEncoding(encoding);
         chain.doFilter(request, response);
           } public void init(FilterConfig arg0) throws ServletException {
      this.config=arg0;
      this.encoding=arg0.getInitParameter("encoding"); }}
      

  2.   

    这个 小问题呢 你回写一个请求处理器吗?会写的话就能解决,不会的话你可以写一个过滤器呢还不会的话,你的jsp的提交方式为Post的话,就直接在action设置编码,不post的话,你就在servlet.xml配置文件里面该一下就行呢?具体怎么做,你可以去网上收收,乱码很好解决呢