教程集 www.jiaochengji.com
教程集 >  脚本编程  >  java  >  正文 jsp中页面间传汉字参数转码

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

发布时间:2016-11-27   编辑:jiaochengji.com
教程集为您提供jsp中页面间传汉字参数转码等资源,欢迎您收藏本站,我们将为您提供最新的jsp中页面间传汉字参数转码资源
在url地址栏传参数如果我们直接使用汉字可能有朋友会发现接受到的是乱码了或在搜索引擎过去都变乱了,下面我们来看看正确的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源代码

<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('copy9136')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy9136>

<%@ 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及语法概要

[关闭]
~ ~