jsp中页面间传汉字参数转码
转码:a.href="./showCont.jsp?tcontent=" encodeURI(encodeURI(tcontent));
解码:java.net.URLDecoder.decode((String)request.getParameter("tcontent"), "UTF-8");
例
a.jsp源代码
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy8747')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy8747><%@ 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>
您可能感兴趣的文章:
jsp中页面间传汉字参数转码
JSP常见问题
jsp常见问题二
JSP入门教程(3)-HTML表单
JSP面试题与答案讲解
JSP开发入门(4)-JSP的内部对象
在Jsp程序读取或向DB写入数据乱码解决办法
ASP与JSP的比较(一)
JSP入门教程(4)-使用脚本
servlet与jsp基础教程(11)-JSP及语法概要