在jsp页面使用UTF-8编码方式,就没有这些问题了。

解决方案 »

  1.   

    写一个Filter类
    package Filter;import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;/**
     * <p>Title: struts w\u03F0</p>
     * <p>Description: struts w\u03F0</p>
     * <p>Copyright: Copyright (c) 2004</p>
     * <p>Company: wsd</p>
     * @author wubai
     * @version 1.0
     */public class SetCharacterEncodingFilter extends HttpServlet implements Filter {
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
               throws ServletException, IOException {
            request.setCharacterEncoding("GBK");
            response.setContentType("text/html;charset=GBK");
            chain.doFilter(request, response);
        }    public void init(FilterConfig config) throws ServletException{
        }    public void destroy(){
        }
    }然后在WEB应用的web.xml中配制一下<filter>
        <filter-name>SetCharacterEncoding</filter-name>
        <filter-class>Filter.SetCharacterEncodingFilter</filter-class>
      </filter>
      <filter-mapping>
        <filter-name>SetCharacterEncoding</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>
      

  2.   

    楼上的: 类就不用写了吧,在Tomcat 5.0的example中就有!!
    xml文件也有,只接拷就OK了
      

  3.   

    laughter75(汤姆.凯特) 说的对,我就是直接拷的,我就不明白的是为什么用了Filter还离不开"<%@ page contentType="text/html;charset=gb2312"%>"
      

  4.   

    window底下的服务器我没试过,不过在linux下,我一直都是加这一行"<%@ page contentType="text/html;charset=gb2312"%>",然后写入数据库都转换为ISO码,读出时再转换为gb码。
      

  5.   

    其实主要的问题就是集中在如何使一套页面代码能够适应所有版本的TOMCAT的中文问题.会不会很难啊?如果每次都要String s1=new String(s.getBytes(iso-8859-1));的话,恐怕...
    牛人们有没有什么比较好的办法?
      

  6.   

    乱码的问题过去已经回答过很多次了,你去
    http://community.csdn.net/Expert/FAQ/List_Room_FAQ_Index.asp?Roomid=5409
    看看,有很多关于乱码的问题,而且都已经成功的解决了。
      

  7.   

    to AHUA1001(99) :
    最新的tomcat 5.0.27中又有新问题了.
    经过测试我发现:
    比如说我有N个JSP,我不想每个都加上<%@ page contentType="text/html;charset=GBK"%>,所以我把这一句放到一个jsp中,然后每个JSP都加上<%@ include file="/include/global.jsp"%>,但是这样做好象中文不能显示正常,似乎include指令好象不是单纯的静态包含.
      

  8.   

    tomcat:
    从表单读的时候 转到GBK从数据库体的时候 转回GB2312resin 直接加个<%@ page contentType="text/html;charset=GBK"%> ok了
      

  9.   

    kingapex1(忘掉将来)的方法有点麻烦,每次都要转化,做个filter就可以了.
      

  10.   

    <% request.setCharacterEncoding("GB2312");%>
      

  11.   

    to viano(我爱十三妹子) :
    <% request.setCharacterEncoding("GB2312");%>
    在tomcat5中对post是没有用的.
      

  12.   

    to viano(我爱十三妹子) :
    <% request.setCharacterEncoding("GB2312");%>
    在tomcat5中对post是没有用的.