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

jsp页面间传中文参数示例(页面传参数编码)

程序员文章站 2023-11-17 23:12:04
转码:复制代码 代码如下:a.href="./showcont.jsp?tcontent="+encodeuri(encodeuri(tcontent)); 解码:复制代...

转码:

复制代码 代码如下:

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>