【www.gdgbn.com--js教程】

最近在学JSP,和大多数新手一样遇到了中文显示问题,中文问题有两种:
(1)页面本身的出现的中文,解决办法为JSP页面开头加入的
       <%@ page language="java" contentType="text/html;charset=GB2312" pageEncoding="GB2312"%>
    或是<%@ page language="java" contentType="text/html;charset=GB2312"%>
  或是将上面出现的GB2312改为GBK也行,这样JSP页面出现的中文将正确显示。

(2)JSP页面中请求的参数的值为中文,既request.getParameter("attributeName")得到的值为中文,这样不加什么设置的话,显示也会出问题,解决方法有两种
       1)在所有的request.getParameter("attribute")出现之前,加上
            request.setCharacterEncoding("GB2312");
            或request.setCharacterEncoding("GBK");
       2)第二种方法是在每条String attributeName=request.getParameter("attributeName")语句之后加上
           attributeName=new String(attributeName.getBytes("ISO-8859-1"),"GB2312");
           或attributeName=new String(attributeName.getBytes("ISO8859_1"),"GB2312");
          或attributeName=new String(attributeName.getBytes("ISO-8859-1"),"GBK");
PS:标明为1)和2)的方法不能同时使用,否则同时失效,只能使用其中一种方法

本文来源:http://www.gdgbn.com/wangyezhizuo/14214/