欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

jsp中页面间传汉字参数转码的方法

程序员文章站 2023-11-17 23:12:46
转码:a.href="./showcont.jsp?tcontent="+encodeuri(encodeuri(tcontent)); 解码:java.net.urld...

转码:a.href="./showcont.jsp?tcontent="+encodeuri(encodeuri(tcontent));

解码:java.net.urldecoder.decode((string)request.getparameter("tcontent"), "utf-8");


a.jsp源代码

复制代码 代码如下:

<%@ page contenttype="text/html; charset=gb2312" language="java" import="java.sql.*" 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" />
<title>无标题文档</title>
</head>

<body>
<%
       string str_test = "华工";
%>
<form method=post action="b.jsp?test=<%=java.net.urlencoder.encode(str_test) %>">
         <input type="submit" value="submit" name="提交"> 
</form>

</body>
</html>


b.jsp源代码

复制代码 代码如下:

<%@ page contenttype="text/html; charset=gb2312" language="java" import="java.sql.*" 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" />
<title>无标题文档</title>
</head>

<body>

<%
       string str = new string(request.getparameter("test").getbytes("iso8859_1"));
%>
<br>
<%=str %>
</body>
</html>