zoukankan      html  css  js  c++  java
  • *Server对象的URLEncode方法的详细介绍 *

    ---------------------------------------------------------------------------------------------------
    ^_^
    *Server对象的URLEncode方法 *
    Server对象提供了可以用来把任意字符串转换成相应的合法HTTP URL的方法。
    (1) 示例网页代码的功能
    在示例网页中,处理这个功能的代码非常简单,仅仅检查是否单击了URLEncode方法对应的按钮,如果单击了,把对应的文本框中的值传递给Server.URLEncode方法并显示结果:
    If Len(Request.form(“cmdURLEncode”)) Then
    strvalue = Request.form(“txtURLEncode”)
    Response.Write “<B>Results:</B><BR>Server.URLEncode (“ & QUOT & strvalue _
    & QUOT & “) returned <B>” & QUOT & Server.URLEncode(strvalue) _
    & QUOT & “</B><HR>”
    End If
    (2) 对HTML元素和其他链接使用URLEncode
    URLEncode方法更普遍地用于把<A>元素或其他链接的值写到ASP网页。例如,如果在查询字符串中建立了一系列的链接,这;些链接包含来自一个数据库的值,首先应该对这个字符串使用Server.URLEncode方法:
    <%
    strvalue = Request.form(“txtSomevalue”)

    ‘Create the full URL for the link as an HTTP-legal string
    strURL = http://mysite.com/books.asp?title= & Server.URLEncode(“strvalue”)
    ‘Make sure we don't have any non-legal HTML characters in the page text
    strLink = Server.HTMLEncode(“strvalue”)
    %>

    <A HREF=”<% = strURL %>”><% = strvalue %></A>

    如果放入字符串strvalue的值包含标题“Active Server Pages?”,将得到由这个代码段创建的如下所示的HTML:
    <A HREF=http://mysite.com/books.asp?title=Active+Server+Pages%A9>
    Active Server Pages?</A>
    注意,我们不仅仅使用Server.URLEncode方法来建立一个合法的URL字符串,而且还对链接的文本使用了Server.HTMLEncode方法,以确保把所有非法的字符转换为合适的HTML等价实体。
    和HTMLEncode方法一样,不用反译码ASP网页中的URL编码值。IIS自动地实现URL编码字符串的转换,该字符串在HTTP请求中转换为它们原先格式,使得它们在内置对象中是可用的。

  • 相关阅读:
    leetcode5 Longest Palindromic Substring
    leetcode17 Letter Combinations of a Phone Number
    leetcode13 Roman to Integer
    leetcode14 Longest Common Prefix
    leetcode20 Valid Parentheses
    leetcode392 Is Subsequence
    leetcode121 Best Time to Buy and Sell Stock
    leetcode198 House Robber
    leetcode746 Min Cost Climbing Stairs
    tomcat下使用druid配置jnid数据源
  • 原文地址:https://www.cnblogs.com/dwjaissk/p/341925.html
Copyright © 2011-2022 走看看