该页面的的编码格式是:gb2312,code如下:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.util.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
但是页面的汉字,包括表格的表头的汉字都是问号,数据库里的中文数据不乱码,从数据库取到页面的中文数据在控制台打印出来不乱码,但是显示后全是?,请各位大侠指点一下 ,需要贴什么代码我再贴上来....先谢谢

解决方案 »

  1.   

    开发工具和JSP页面,配置文件等所有的编码要统一!乱码问题根本原因就是编码不统一!
      

  2.   

    建议都用国际编码UTF-8另+过滤器万无一失。
      

  3.   

    加一个过滤器,就可以了
    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);
    }
    }
      

  4.   

    UTF-8我试了,不行;4楼的那个过滤器也用了,还是不行
      

  5.   

    不管是选gb2312还是选择UTF-8都不行...
      

  6.   

    有很多地方值得注意,源程序的编码。jsp的编码,DB的编码,如果有js写url也要编码。
      

  7.   

    过滤器: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 CharFilter implements Filter {
    private String charset = "utf-8"; public void destroy() { } public void doFilter(ServletRequest request, ServletResponse response,
    FilterChain arg2) throws IOException, ServletException {
    request.setCharacterEncoding(charset);
    arg2.doFilter(request, response);
    } public void init(FilterConfig arg0) throws ServletException {
    charset = arg0.getInitParameter("charset");
    }
    }
    web.xml文件里 <filter>
    <filter-name>CharsetFilter</filter-name>
    <filter-class>CharFilter</filter-class>
    <init-param>
    <param-name>charset</param-name>
    <param-value>utf-8</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>CharsetFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <url-pattern>*.do</url-pattern>
    <url-pattern>*.jsp</url-pattern>
    </filter-mapping>
      

  8.   

    servlet  code:
    response.setContentType("text/html");
    response.setCharacterEncoding("utf-8");
    jsp页面 code:
    <%@ page contentType="text/html; charset=utf-8" language="java" import="java.util.*" errorPage="" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="pragma" content="no-cache"/> 
         <meta http-equiv="cache-control" content="no-cache"/> 
         <meta http-equiv="expires" content="0"/> 
    再加上14楼的过滤器,还是不行...........  
      

  9.   

    我把jsp页面的源文件贴上来,让大家帮助我分析.....
    code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="pragma" content="no-cache"/> 
         <meta http-equiv="cache-control" content="no-cache"/> 
         <meta http-equiv="expires" content="0"/>   
    <title>??????</title>
    <link rel="stylesheet" rev="stylesheet" href="css/common.css" type="text/css" media="all" />
    <script type="text/javascript">
    function adddept(){
    location.href="servlet/DeptService?code=alldept&dep=ad";
    }
    function deldept(deptid){
    var flog = confirm("????????");
    if(flog==true){
    location.href="servlet/DeptService?code=deladept&deptid="+deptid;
    }
    }
    </script> 

    <body>
    <div id="man_zone">
    <div align="right">&quot;<input type="button" value="??????"/></div>
    <br/>

    <table width="90%" border="0" align="center"  cellpadding="3" cellspacing="1" class="table_style">
    <tr align="center">
      <td width="233"><span class="left-title">??????</span></td>
      <td width="236"><span class="left-title">??????</span></td>
      <td width="236"><span class="left-title">???????</span></td>
      <td width="170"><span class="left-title">??&nbsp;&nbsp;&nbsp;&nbsp;??</span></td>
    </tr>

    <tr align="center">
      <td>null</td>
      <td>??????</td>
      <td></td>
      <td><a href="DeptService?code=deladept&deptid=62">???</a>&nbsp;&nbsp;&nbsp;<a href="#" onClick="deldept(62)">???</a></td>
    </tr>

    <tr align="center">
      <td>00001</td>
      <td>??????</td>
      <td></td>
      <td><a href="DeptService?code=deladept&deptid=21">???</a>&nbsp;&nbsp;&nbsp;<a href="#" onClick="deldept(21)">???</a></td>
    </tr>

    <tr align="center">
      <td>00002</td>
      <td>?????</td>
      <td></td>
      <td><a href="DeptService?code=deladept&deptid=22">???</a>&nbsp;&nbsp;&nbsp;<a href="#" onClick="deldept(22)">???</a></td>
    </tr>
      
    </table>
    </div>
    </body>
    </html>
    一个问号代表一个汉字.期待详细解答......
      

  10.   

    你的工程編碼是什麽?工程編碼,數據庫編碼,頁面編碼,三方統一. 試下GBK
      

  11.   

    你开发工具是什么?
    MyEclipse右键工程选属性,把编码改成你页面的编码,里面的几个编码都试试 --!
      

  12.   

    查看你的数据库的编码是什么? 估计是数据库的编码问题,之前我们公司的也是,是因为DB里面的编码不同造成的.mysql在create Database的时候加上 : ENGINE=InnoDB DEFAULT CHARSET=gbk;
      

  13.   

    不是create database是create table 的时候!!!!
      

  14.   

    jsp页面编码问题跟浏览器也有关的,你可以将浏览器编码设置与jsp一样...
      

  15.   

    很有可能是数据库编码的问题。统一就好。最好全都是UTF-8.
      

  16.   

    个人觉得这跟过滤器,编码转码之类的没关系.因为它是JSP页面上中文全是乱码,应该和页面设置的编码有关,建议改下编码试试.
      

  17.   

    将页面和工程进行统一一下,建议用UTF-8.过虐器是处理服务时加上,JSP面乱码,可能是你在编写的时候没有改,所以保存后就是乱码了,个人建议重新编写保存时改成UTF-8.
      

  18.   

    在做工程的时候,最好先改一下,ECLIPSE JSP .JS 都改成统一的UTF-8再进行操作,,------个人建议,
      

  19.   

    不好意思,最近有点忙,一直都没有上来。问题已经解决,用的过滤器,14#的那个再加一句:
    public void doFilter(ServletRequest request, ServletResponse response,
                FilterChain arg2) throws IOException, ServletException {
            request.setCharacterEncoding(charset);
            response.setCharacterEncoding(charset);
            arg2.doFilter(request, response);
    }
    这样就解决了,但是引起这样原因我还是不知道,哪位高手能解答,希望给一下,谢谢
      

  20.   

    感谢lz
    加了一句response.setCharacterEncoding("UTF-8");就解决了