加 response.setContentType("gb2312") 试

解决方案 »

  1.   

    <%@ page language="java"  import="java.sql.*"  contentType = "text/html; charSet=gb2312" %>
      

  2.   

    <meta http-equiv="Content-Language" content="zh-cn">
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
      

  3.   

    我说一下我的经历吧:    我暑假的时候在自己机子上调试的时候也出现中文问题,而且还没有一个固定的处理方法
    有时候加上<%@ page contentType = "text/html; charSet=gb2312" %>就可以了,有时候要
    在得到字符串以后在重新编码才能正常显示。后来移到了服务器上(linux+resin),本来正常的又不能显示了,后来我干脆把所有的中文处理得都去掉了(包括<meta http-equiv="Content-Type" content="text/html; charset=gb2312">),结果反而是正确的。
        在清华的bbs上看过:要解决中文问题的第一步是看看你有没有中文问题:)
      

  4.   

    在weblogic或tomcat上可增加request.setCharacterEncoding("GBK");试试
      

  5.   

    解决java中文问题:
    针对applet和awt:
        1:)
        Font f = new Font(UIResource.getString(      "Default_font"),Font.PLAIN,12);
          UIManager.put("Label.font",f);
          UIManager.put("Label.foreground",Color.black);
          UIManager.put("Button.font",f);
          UIManager.put("Menu.font",f);
          UIManager.put("MenuItem.font",f);
          UIManager.put("List.font",f);
          UIManager.put("CheckBox.font",f);
          UIManager.put("RadioButton.font",f);
          UIManager.put("ComboBox.font",f);
          UIManager.put("TextArea.font",f);
        2:)
          Font f = new Font("隶书",Font.PLAIN,15);
               UIManager.put("Button.font",font);
      UIManager.put("ToggleButton.font",font);
      UIManager.put("RadioButton.font",font);
      UIManager.put("CheckBox.font",font);
      UIManager.put("ColorChooser.font",font);
      UIManager.put("ToggleButton.font",font);
      UIManager.put("ComboBox.font",font);
      UIManager.put("ComboBoxItem.font",font);
      UIManager.put("InternalFrame.titleFont",font);
      UIManager.put("Label.font",font);
      UIManager.put("List.font",font);
      UIManager.put("MenuBar.font",font);
      UIManager.put("Menu.font",font);
      UIManager.put("MenuItem.font",font);
      UIManager.put("RadioButtonMenuItem.font",font);
      UIManager.put("CheckBoxMenuItem.font",font);
      UIManager.put("PopupMenu.font",font);
      UIManager.put("OptionPane.font",font);
      UIManager.put("Panel.font",font);
      UIManager.put("ProgressBar.font",font);
      UIManager.put("ScrollPane.font",font);
      UIManager.put("Viewport",font);
      UIManager.put("TabbedPane.font",font);
      UIManager.put("TableHeader.font",font);
      UIManager.put("TextField.font",font);
      UIManager.put("PasswordFiled.font",font);
      UIManager.put("TextArea.font",font);
      UIManager.put("TextPane.font",font);
      UIManager.put("EditorPane.font",font);
      UIManager.put("TitledBorder.font",font);
      UIManager.put("ToolBar.font",font);
      UIManager.put("ToolTip.font",font);
      UIManager.put("Tree.font",font); 3:)针对jsp和servlet:
    解决办法:
    第一:
    在jsp页面加入:
    <%@ page contentType="text/html; charset=gb2312" %>
    或者在servlet里面
      public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html; charset=gb2312");//这是重要的
    上面的如果在不行就用如下的方法在数据入库前进行调用:
    public static String UnicodeToChinese(String s){
      try{
         if(s==null||s.equals("")) return "";
         String newstring=null;
         newstring=new String(s.getBytes("ISO8859_1"),"gb2312");
         return newstring;
        }
      catch(UnsupportedEncodingException e)
      {
      return s;
      }
      }public static String ChineseToUnicode(String s){
      try{
      if(s==null||s.equals("")) return "";
      String newstring=null;
      newstring=new String(s.getBytes("gb2312"),"ISO8859_1");
       return newstring;
      }
      catch(UnsupportedEncodingException e)
      {
      return s;
     }
      }3:)解决weblogic/webshpere中文问题:
    在web.xml文件中需要配置中文环境。r如下:
    <context-param>
      <param-name>weblogic.httpd.inputCharset./*</param-name>
      <param-value>GB2312</param-value>
    </context-param>
      4:)javamail附件中文乱码:
    /*
            @从BodyPart中提取使用ISO-8859-1编吗的文件名
            @因为BodyPart.getFilename()过程已经对文件名作了一次编码,有时不能直接使用
        */
        public static String getISOFileName(Part body){
            //设置一个标志,判断文件名从Content-Disposition中获取还是从Content-Type中获取
            boolean flag=true;
            if(body==null){
                return null;
            }
            String[] cdis;
            try{
                cdis=body.getHeader("Content-Disposition");
            }
            catch(Exception e){
                return null;
            }
            if(cdis==null){
                flag=false;
            }
            if(!flag){
                try{
                    cdis=body.getHeader("Content-Type");
                }
                catch(Exception e){
                    return null;
                }
            }
            if(cdis==null){
                return null;
            }
            if(cdis[0]==null){
                return null;
            }
            //从Content-Disposition中获取文件名
            if(flag){
                int pos=cdis[0].indexOf("filename=");
                if(pos<0){
                    return null;
                }
                //如果文件名带引号
                if(cdis[0].charAt(cdis[0].length()-1)=='"'){
                    return cdis[0].substring(pos+10,cdis[0].length()-1);
                }
                return cdis[0].substring(pos+9,cdis[0].length());
            }
            else{
                int pos=cdis[0].indexOf("name=");
                if(pos<0){
                    return null;
                }
                //如果文件名带引号
                if(cdis[0].charAt(cdis[0].length()-1)=='"'){
                    return cdis[0].substring(pos+6,cdis[0].length()-1);
                }
                return cdis[0].substring(pos+5,cdis[0].length());
            }
        }
      

  6.   

    我现在发现了我即使在写HTML文件的时候也是乱码,我用的是LINUX8。0我也是在他的下面开发的,我用它的记事本进行开发的,写中文可以,但是只要用浏览器他就是乱码了,另外我在LINUX下找到一个做网页的工具,可以进行中文输入,浏览也没有乱码,可是他却把我写的JSP代码当作文本显示出来了。谢谢你们希望大家帮帮忙。
      

  7.   

    <%@page contentType="text/html;charset=gb2312"%>加上它
      

  8.   

    http://expert.csdn.net/Expert/topic/1085/1085595.xml?temp=7.183254E-03