您的位置:首页 > 其它

再不更改web.config文件的条件下---Script 中url传中文参数(解密) 接收时解密。。。。

2007-11-13 13:26 483 查看
关于javascript编码url的中文参数
做中文站点,在url中使用中文参数太正常了,比如:http://website/list.asp?keyword=关键字
在理想状态下,是不需要做任何的处理,list.aspx页面可以接收到“关键字”这个中文参数,但相当一部分情况下,会得到乱码,所以为了安全保险起见,我们还是要对中文字符作一下编码,编码很简单

var s1= '中文参数';
var s2 = escape( s1 );
alert( s2 );

通常情况下,list.aspx页面会对传入的已经编码的参数自动处理(用debug跟踪调试的时候可以看到),但不能保证所有人的程序都会这样,我自己就遇到接收过来还是类似:%uXXXX这样的字符串,所以最安全的方法,就是我们利用.net提供的方法,解码一下。

string KeyWorld = Server.UrlDecode( Request.QueryString["keyword"] );

<script language="javascript">
function showCustomer()
{
//var txtName =document.getElementById("txtCusName")
var txtCode = document.getElementById("txtCusCode")
//var content=document.all(
//alert(Form1.txtName.value)
var content=Form1.txtName.value
var gmcode=Form1.gmcode.value
if (content=="")
{
alert("请输入检索的内容!")
return;
}
var url="showDialog/showCustomers.aspx?content="+escape(content)+"&gmcode="+gmcode

//alert(url)
var returns = showModalDialog(url,window,"dialogHeight: 400px; dialogWidth: 550px; dialogTop: 180px; dialogLeft: 300px; center: yes; help: no");

if (returns != null)
{
if (returns.length == 2)
{
Form1.txtName.value = returns[1]
txtCode.value = returns[0]
}
}
}
</script>

Private Sub Bind_DG()
Dim user As Cls_User = CType(Session("user"), Cls_User)
If Not user Is Nothing Then
Dim dt As DataTable
If user.cRoleID.Trim = "007" Then
dt = Cls_customer.Get_Manager_Customer(user.cDepCode.Trim, user.cUserCode, user.Type.Trim, Server.UrlDecode(Request.QueryString("content")))
Else
If user.cRoleID.Trim = "001" Or user.cRoleID = "002" Or user.cRoleID = "003" Or user.cRoleID = "004" Or user.cRoleID = "008" Then
dt = Cls_customer.Get_Dep_Customer(user.Type.Trim, Request.QueryString("gmcode"), Server.UrlDecode(Request.QueryString("content")))
Else
dt = Cls_customer.Get_Dep_Customer(user.Type.Trim, user.cDepCode.Trim, Server.UrlDecode(Request.QueryString("content")))
End If
End If

dgCustomer.DataSource = dt
dgCustomer.DataBind()
dgCustomer.Height = Unit.Pixel(30)
End If
End Sub

function showCustomer()
{
//var txtName =document.getElementById("txtCusName")
var txtCode = document.getElementById("txtCusCode")
//var content=document.all(
//alert(Form1.txtName.value)
var content=Form1.txtName.value
var gmcode=Form1.gmcode.value
if (content=="")
{
alert("请输入检索的内容!")
return;
}
var url="showDialog/showCustomers.aspx?content="+escape(content)+"&gmcode="+gmcode

//alert(url)
var returns = showModalDialog(url,window,"dialogHeight: 400px; dialogWidth: 550px; dialogTop: 180px; dialogLeft: 300px; center: yes; help: no");

if (returns != null)
{
if (returns.length == 2)
{
Form1.txtName.value = returns[1]
txtCode.value = returns[0]
}
}
}

在不更改web.config文件的条件下。。实现中文传递参数。。。

<!-- 全球化 此节设置应用程序的全球化设置。
<globalization requestEncoding="gb2312" responseEncoding="gb2312"/>-->

传递-----escape("字符串") -------主要就是这个函数起作用。。。

接收------Sever.UrlDecode("字符串")--------接收时实现解密。。。。。

function showCustomer()
{
//var txtName =document.getElementById("txtCusName")
var txtCode = document.getElementById("txtCusCode")
//var content=document.all(
//alert(Form1.txtName.value)
var content=Form1.txtName.value
var gmcode=Form1.gmcode.value
if (content=="")
{
alert("请输入检索的内容!")
return;
}
var url="showDialog/showCustomers.aspx?content="+escape(content)+"&gmcode="+gmcode

//alert(url)
var returns = showModalDialog(url,window,"dialogHeight: 400px; dialogWidth: 550px; dialogTop: 180px; dialogLeft: 300px; center: yes; help: no");

if (returns != null)
{
if (returns.length == 2)
{
Form1.txtName.value = returns[1]
txtCode.value = returns[0]
}
}
}

function showCustomer()
{
//var txtName =document.getElementById("txtCusName")
var txtCode = document.getElementById("txtCusCode")
//var content=document.all(
//alert(Form1.txtName.value)
var content=Form1.txtName.value
var gmcode=Form1.gmcode.value
if (content=="")
{
alert("请输入检索的内容!")
return;
}
var url="showDialog/showCustomers.aspx?content="+escape(content)+"&gmcode="+gmcode

//alert(url)
var returns = showModalDialog(url,window,"dialogHeight: 400px; dialogWidth: 550px; dialogTop: 180px; dialogLeft: 300px; center: yes; help: no");

if (returns != null)
{
if (returns.length == 2)
{
Form1.txtName.value = returns[1]
txtCode.value = returns[0]
}
}
}

function showCustomer()
{
//var txtName =document.getElementById("txtCusName")
var txtCode = document.getElementById("txtCusCode")
//var content=document.all(
//alert(Form1.txtName.value)
var content=Form1.txtName.value
var gmcode=Form1.gmcode.value
if (content=="")
{
alert("请输入检索的内容!")
return;
}
var url="showDialog/showCustomers.aspx?content="+escape(content)+"&gmcode="+gmcode

//alert(url)
var returns = showModalDialog(url,window,"dialogHeight: 400px; dialogWidth: 550px; dialogTop: 180px; dialogLeft: 300px; center: yes; help: no");

if (returns != null)
{
if (returns.length == 2)
{
Form1.txtName.value = returns[1]
txtCode.value = returns[0]
}
}
}

function showCustomer()
{
//var txtName =document.getElementById("txtCusName")
var txtCode = document.getElementById("txtCusCode")
//var content=document.all(
//alert(Form1.txtName.value)
var content=Form1.txtName.value
var gmcode=Form1.gmcode.value
if (content=="")
{
alert("请输入检索的内容!")
return;
}
var url="showDialog/showCustomers.aspx?content="+escape(content)+"&gmcode="+gmcode

//alert(url)
var returns = showModalDialog(url,window,"dialogHeight: 400px; dialogWidth: 550px; dialogTop: 180px; dialogLeft: 300px; center: yes; help: no");

if (returns != null)
{
if (returns.length == 2)
{
Form1.txtName.value = returns[1]
txtCode.value = returns[0]
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: