再不更改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]
}
}
}
做中文站点,在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]
}
}
}
相关文章推荐
- url传中文参数的时候,乱码,需要对web.config配置
- common fileUpload 接收文件以外的参数和中文乱码的问题
- 正在进行生成的同时试图签出,因为无法对必须修改的文件"Web.config"进行更改...
- PetShop 4.0知识点:加密和解密Web.config文件的配置节
- web.config文件的中文解释
- Spring 管理下的web项目,对Properties文件重要参数的加密解密处理(续)
- JAVA web 开发中URL链接中文参数乱码问题
- c# web.config 配置文件的加密与解密,aspnet_regiis.exe
- aspnetpager多参数URL重写在webconfig中, "&"这个字符的问题,&转义失败
- ASP.NET 2.0加密解密Web.config配置文件
- URL参数带中文,后台接收乱码解决方案
- URL中文传参,后台接收参数乱码
- PetShop 4.0知识点:加密和解密Web.config文件的配置节
- 填上浏览器跳转app-webview,app没有接收跳转url的查询参数的坑
- MemberShip,角色,WebPart在web.config文件中的参数简述
- 更改Web.config中对上传文件大小限制
- WEB系统中加密\解密URL传输参数(EIP.Framework中的实现)
- 无效的过程调用或参数: 'leftB' 与web.config 文件的 system.webServer/httpErrors 节中不允许绝对物理路径“C:/inetpub/custerr”。请改用相对路径解决办法
- web.config文件的中文解释
- 简单解决 multipart/form-data 文件上传表单中 传递参数无法获取的办法! (解决办法:动态更改表单提交URL)