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>
下一篇: PHP 中的关于 trait 的简单