在4.0以后的版本,已经不需要象3.23版本中使用字符转换函数:(1)编译javabean时 javac 命令行加上-encoding ISO8859_1(2)在Jsp头部中加入<%@ page contentType="text/html;charset=ISO8859_1" %>

解决方案 »

  1.   

    public static String getStr(String strInString)
      {
        try {
          return new String(strInString.getBytes("ISO8859-1"),"gb2312");
        }
        catch (Exception ex) {
          return "";
        }
      }
      public static String charToISO(String strInString){
        try {
          return new String(strInString.getBytes("gb2312"),"ISO8859-1");
        }
        catch (Exception ex) {
          return "";
        }
      }
    .....
    String ranmessage = getStr(message);
    response.sendRedirect("login.jsp?message="+ranmessage);
      

  2.   

    <%@ page contentType="text/html;charset=ISO8859_1" %>
    charToISO(message)
    都可以解决,但是charToISO(message)在Tomcat下又显示乱码,所以选择<%@ page contentType="text/html;charset=ISO8859_1" %>谁能解释一下字符集的问题,什么服务器用的是什么字符集,我什么时候该用什么样的字符集1.往数据库里存数据
    2.从数据库里读出数据显示
    3.通过url传递参数时解决完这个问题马上结帖
      

  3.   

    解决办法:
    第一:
    在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;
     }
      }
      

  4.   

    <%@ page contentType="text/html;charset=ISO8859_1" %>
      

  5.   

    <%@ page contentType="text/html; charset=gb2312" %>
    加上这个在页面上一定行的,我想是这样的,我的网页都有的,不知道是我的对不对,不对的地方请多多指教。
      

  6.   

    如果在你的URL中需要传递中文,就用java.net.URLEncoder.encode()进行编码,这样就可以解决了。
    示例:
    <a href=hello.jsp?send=<%=java.net.URLEncoder.encode("大家好")%>> 点击</a>
    在接受页面上面加上
    <%@ page contentType="text/html; charset=gb2312" %>
    如果要将数据插入数据库要做处理的
    如将content的内容插入数据库,就要处理一下。
    content = new String(content.getBytes("ISO8859_1"),"GB2312") ;