Java,J2EE,Weblogic,Oracle

java项目随笔
随笔 - 90, 文章 - 6, 评论 - 61, 引用 - 0
数据加载中……

jsp之间中文传值的问题,中文URL传值时的处理



         String test="中文测试";
           String temp=URLEncoder.encode(test,"GBK");   //编码
           System.out.println(temp);
   
        String test2=URLDecoder.decode(temp,"GBK"); //解码
           System.out.println(test2);

         String h4="中文测试";
          String h5=URLEncoder.encode(h4,"utf-8");
          System.out.println(h5);  
         String h6=URLDecoder.decode(h5,"utf-8");
         System.out.println(h6);


以上代码在java类中测试没问题。但在jsp之间传值却行不通,jsp之间只能通过另外一种方式,
例如两个jsp  : A1.jsp,A2.jsp
(1)A1.jsp 默认编码为 utf-8,即<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> ,
     例如:A1.jsp 调用javascript (或response.sendRedirect()跳转)向A2.jsp传值,
    window.open(A2.jsp?name="中文测试","newwindows","toolbar=no,location=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=no");
(2)A2.jsp  接收代码应该为:
    String  name=new String(request.getParameter("name").toString().trim().getBytes("ISO8859_1"),"utf-8");

同理如果A1.jsp 默认编码为 gbk ,即<%@ page language="java" contentType="text/html; charset=gbk" pageEncoding="gbk"%> 。则A2.jsp接收代码应该为 String  name=new String(request.getParameter("name").toString().trim().getBytes("ISO8859_1"),"gbk");

posted on 2007-06-27 14:20 龚椿深 阅读(4390) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: