在传统的ASP传递变量 [英] Passing variables in classic ASP

查看:654
本文介绍了在传统的ASP传递变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我处理遗留code,其中有一个包含另一个ASP页。

I am dealing with legacy code where there is an include of another ASP page.

<!--#INCLUDE virtual="/PAGE1.ASP"-->

得到一个变量,例如x,从该网页,我beleive我会做:

to get a variable, say x, from that page, I beleive I would do:

x = Request.Form("x")

是正确的?

此外,是变量名称区分经典.ASP文件中的敏感?

Also, are the variable names case sensitive for classic .ASP files?

太感谢了。

推荐答案

您应该把页面被建造成为一个连续页,所以如果你有一些的.asp 的文件,他们将建立完成的网页。

You should think of the page as being built into one contiguous page, so that if you include a number of .asp files they will build up your finished page.

举例来说,如果你有三个文件:

For instance, if you have three files:

File_1.asp

<h1>Hello, World!</h1>

File_2.asp

<p>This file will be included too!</p>

File_3.asp

<%Dim version
version = 1.1%>

...并把它们包含在一个核心文件...

...and include them in one core file...

File_Output.asp

<!-- #include virtual="file_1.asp" -->
<!-- #include virtual="file_2.asp" -->
<!-- #include virtual="file_3.asp" -->
<% Response.Write(version) %>

File_Output.asp 会在版本 File_3.asp

有关于它一个可爱的小文章在这里

There's a nice little article about it here.

- 编辑 -

我想补充(错过了你的帖子的末尾的问题):

Just to add (having missed the question at the end of your post):

区分大小写依赖于传统ASP使用的脚本语言。使用VBScript变量名称是区分的敏感,而,使用JScript(其中,语法是非常像的JavaScript)变量的的区分大小写。

Case sensitivity depends on the scripting language used by Classic ASP. With VBScript variable names are case insensitive, whereas, with JScript (which, syntactically, is very much like JavaScript) variables are case sensitive.

此外,为解决 ERR 对象:

有一个伟大的小片这里,但去的基本事实,你需要用你的code在错误捕获块,像这样:

There's a great little piece here, but to get to the nitty-gritty, you need to wrap your code in an error catching block like so:

On Error Resume Next    '<-- This line starts trapping errors
    ...
On Error Goto 0         '<-- This line stops trapping errors

如果确实发生在该块中,需要处理的错误信息。不像ASP.NET,爪哇,等等,等等,你不是说有一个错误;有没有好的的try ... catch 包装很好地处理错误。你必须种的 predict 的哪里会发生错误。通常这是显而易见的。如果你在你的脚本有数据库操作这是一个好主意,以测试是否有错误后直接读取或写入数据。检查错误很简单 - 你测试 ERR 对象的编号属性:

If an error does occur in this block you need to deal with it. Unlike ASP.NET, Java, etc. etc., you are not told that there is an error; there is no nice Try...Catch wrapper to handle the errors nicely. You must kind of predict where the error will happen. Usually it's obvious. If you have database manipulation in your script it's a good idea to test for errors directly after your data read or write. To check for errors is simple - you test the Number property of the Err object:

On Error Resume Next    '<-- This line starts trapping errors
    'Some database manipulation...
    If Err.Number <> 0 Then
        ... 'Handle the error
    End If
On Error Goto 0         '<-- This line stops trapping errors

这可以扩展到兼顾不同的错误信息:

This can be expanded to take into account different error messages:

On Error Resume Next    '<-- This line starts trapping errors
    'Some database manipulation...
    Select Case Err.Number
        Case 1
            ... 'Handle the error
        Case 2
            ...
        Case 3021 'No data returned
            Response.Write("No data was returned.")
    End Select
On Error Goto 0         '<-- This line stops trapping errors

希望这有助于。

这篇关于在传统的ASP传递变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆