不是jsp就是java程序,网上提供的方法太多了,但是好像都不行
改set name gbk

很多,很多
希望真正懂的人提供经典的方法。

解决方案 »

  1.   

    在jsp页面中出现乱码:
    你可以用像这样的语句来处理,ISO-8859-1是网上统一的一种编码方式:  (Stringname.getBytes("ISO-8859-1"),"GBK")在MYSQL中的乱码:你可以在建表的时候指定字符集,形如这样:
    CREATE TABLE tableNAme
    (
      ......
      )default character set gbk;我是在XP用的Mysql5。。
      

  2.   

    http://topic.csdn.net/u/20071124/08/3b7eae69-ed1d-4a77-8895-9930bf3601af.html
      

  3.   

    我这里有一个解决jsp调用MYSQL数据中文乱码问题的解决办法,不知道适合你的没有。
    我的数据服务器与网站服务器:MYSQL5.0+Tomcat5.0.28+JSP。
    1、 把mysql默认字符设置成UTF-82、 在Tomcat加个过滤器  package org.glgk.card.filters;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 SetCharacterEncodingFilter 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;     }     protected String selectEncoding(ServletRequest request) {         return (this.encoding);     } 
    }Web.xml
    <filter>
        <filter-name>Set Character Encoding</filter-name>
        <filter-class>org.glgk.card.filters.SetCharacterEncodingFilter</filter-class>
        <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
        </init-param>
        </filter>
        
        <filter-mapping>
        <filter-name>Set Character Encoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>3、 每个JSP页面增加
       <%@ page language="java" contentType="text/html; charset=UTF-8"%>
      

  4.   

    我跟你说 实际上很简单 修改my.ini 找到[mysql]和[mysqld]的default-character-set=latin 改为default-character-set=gbk 这就相当于修改了mysql服务器和客户端连接通信以及储存数据的方式. 重启mysql服务控制面板里的服务里面重启.然后通过mysql>show variables like '%char%';查看修改后的字符集.
    下一步就是你程序的处理了..如果你只是简单的jsp和servlet交互那么你就直接在servlet的post方法中(假定你form提交方式为post),设定request.setCharacterEncoding("UTF-8");即可取得的数据为UTF-8格式,但是插入数据库存储格式为gbk中文.struts中的话将web.xml加入楼上所示的filter.所有前台页面和后台页面都使用UTF-8编码.好的 祝你好运.