Asp JavaScript 教程 - Lesson 02 Escape Characters

转载 2006年06月24日 13:16:00
 

Escape Characters

Not Out of Place:

The instruction of Escape Characters in Lesson 02 seems out of place. But it's not. Escape Characters are an integral part of using JavaScript in ASP. Lesson 02 is exactly the right spot for escape characters. Without escape characters, you will struggle to write effective ASP scripts in JavaScript. Sorry.

Get Started:

Below is the ASP Script for Lesson 02.

<%@LANGUAGE="JavaScript"%>
<%
Response.Write("<HTML>/r")
Response.Write("<FONT COLOR=/"red/">/"Hello World/"</FONT><BR>/r")
Response.Write("<FONT COLOR='blue'>'Hello World'</FONT><BR>/r")
Response.Write("</HTML>/r")
%>

Click Here to run the script in a new window.

Remember in Lesson 01 how the entire HTML output was on one line. The escape characters allow us to add carriage returns.

Below is the HTML source code as seen on the client side.

<HTML>
<FONT COLOR="red">"Hello World"</FONT><BR>
<FONT COLOR='blue'>'Hello World'</FONT><BR>
</HTML>

Escape Return:

I've reprinted a single line of ASP script below. Look at the "/r" at the end of the line.

Response.Write("<FONT COLOR=/"red/">/"Hello World/"</FONT><BR>/r")

The "/r" is a special character representing a carriage return. It's how I got the separate lines of HTML output on ...well... separate lines. That's vitally important on larger applications and larger pages. I said it before, but I'll say it again. Trust me; you can't find bugs if you can't even make heads or tails of what you're putting out to the client.

Escape Quote:

There's something else you should notice. See how I put the backslash underneath some of the quotation marks. What would happen if I remove the backslashes? Let's try the following line of code.

Response.Write("<FONT COLOR="red">"Hello World"</FONT><BR>")

I would get an error code, which is copied below.

Microsoft JScript compilation error '800a03ee' 

Expected ')' 

/asp/Section01/Script02.asp, line 4 

Response.Write("<FONT COLOR="red">"Hello World"</FONT><BR>")
-----------------------------^

No Escape:

What if I don't like Escape Characters? Do I have to use them?

You can limp along without them. Consider the line below.

Response.Write("<FONT COLOR='blue'>'Hello World'</FONT><BR>")

/b Backspace
/cD Control-D
/f Form Feed
/n New Line
/r Carriage Return
/t Tab
/xnn Hexadecimal
/0nn ASCII Escape Characters
/' Single Quote
/" Double Quote
// Backslash

You can interchange single quotes with double quotes. It's awkward, in my opinion. But it works. Even with that said, HTML aesthetics are the least important reason to use Escape Characters.

The List:

A far more important reason to utilize escape characters is that it allows us to output a whole list of special characters.

Most Important:

But the most important reason to use Escape Characters (at least for any sophisticated application) is for your database connection. (Database connections get their own lesson later on.) Compare the two Connection Strings below.

var Connection="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("//TopLevelVirtualFolder") + "//database//myDatabase.mdb;"

Dim Connection;
Connection="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("/TopLevelVirtualFolder") & "/database/myDatabase.mdb;"

Next Up:

There's another little tool we absolutely must have to write ASP JavaScript. And that's in lesson 03.

相关文章推荐

C++ SDL教程翻译 Lesson 02 Getting an Image on the Screen

这是第二篇SDL教程的翻译。

URLDecoder异常Illegal hex characters in escape (%)

最近在公司系统上进行二次开发,遇到这样的一个错误URLDecoder异常Illegal hex characters in escape (%) ...,先来介绍下这个开发的结构,首先有一个提供服务的...

[Lesson Learn] LeetCode #3 Longest Substring Without Repeating Characters

在LeetCode上刷题时的学习笔记。

JavaScript基础教程02好神奇的变量var

javascript变量的声明 1.变量是存储信息的容器。 var x=2; var y=3; var z=x+y; 提示:您可以把变量看做存储数据的容器 2.JavaScript 变量命名规...

ASP。NET中的JAVASCRIPT 02

  • 2009-06-19 12:26
  • 334KB
  • 下载

Escape 解决中文乱码(URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "u6")

错误信息: 解决方案: /**  *  * 名称:EscapeToolBox(Escape编码处理工具类)  * 功能:字符串编码和解码,适合对AJAX提交数据进行编码解码处理,解决中文乱...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)