当前位置:首页 > JSP教程 > JSP常见问题

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

转码:

复制代码 代码如下:

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>



【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐