📄 185.html
字号:
<a Name="idx1073747023"></A>
<A NAme="idx1073747024"></a>
</p>
</P></DIV>
<br>
<br>
<P>ASP is not language dependent, and though most of the things you will find in the market are written in VBScript or
JScript, you can actually configure ASP to use any other scripting language that supports the Microsoft ActiveX Scripting
interface. This includes VBScript, JScript, PERLScript, PScript, and of course, Python.</P>
<P>The object model defined by ASP is different from the object model defined by Internet Explorer. The first thing you will
notice is that ASP code has some special tags:</P>
<ul>
<li>
<P>The <TT Class="monofont"><%@ language=Python %></tt> tag defines that all scripting tags after that will, by default, belong to
Python.</p>
</li>
<li>
<p>The <tt class="monofont"><% %></tT> tag is equivalent to <tt ClasS="monofont"><script> </script>.</tt>
</p>
</lI>
<li>
<p>
<TT CLass="monofont"><%= %></tT> allows you to replace part of the contents to be displayed with the value of a variable. For
instance,</P>
<PRe>
<%
name = "Andre" %>
Whassup <%= name %> !
</pre>
</LI>
</UL>
<p>There is no restriction on the commands that you can execute on a ASP page because all the execution takes place at
the Server. Thus, in theory there would be no need for high security procedures. However, there is just as much need for
security in ASP files as in CGI script when you are making use of untrusted input. The fact that there is no sandbox means
you have to be especially careful not to compromise your system.</p>
<diV CLAss="note"><p class="notetitle"><b>Note</b></p><p>
<p>ASP files are stored in files with the <tt class="monofont">.asp</Tt> extension.<a Name="idx1073747025"></A>
<a namE="idx1073747026"></a>
<a nAME="idx1073747027"></A>
<a namE="idx1073747028"></A>
<A Name="idx1073747029"></a>
</P>
</P></DIv>
<br>
<bR>
<P>One last detail about Python/ASP programs is that the <A Name="idx1073747030"></a>
<a name="idx1073747031"></a>
<a name="idx1073747032"></a>
<a namE="idx1073747033"></a>
<a Name="idx1073747034"></A>print statement does not send the information to the screen. You need to use ASP's object model <a namE="idx1073747035"></a>
<a nAME="idx1073747036"></A>
<tt clASS="monofont">Response.Write()</Tt> function to do it, as you can check in the following example.</p>
<prE>
<%@ language=Python %>
<%
text = "this text here does not use the print command" %>
A curious fact is that <%= text %>.
<br>
Note that we still need to pay attention to the indentation in this code.
<br>
The next code block lists all the server variables.
<br><br>
<%
for k in Request.ServerVariables:
v = Request.ServerVariables(k)
Response.Write("<b>%s</b>=" % (k))
Response.Write("%s<br><br>" % (v))
%>
</PRE>
<p>Of course, you could fix the <tt cLASS="monofont">print</tt> statement problem with the following code to make print work
again.</p>
<pre>
class ASPStdout:
def write(self, bytes):
Request.Write(bytes)
def writelines(self, lines):
for line in lines: self.write(line)
sys.stdout = ASPStdout()
</pre>
<p>In case you want to try something different, <a name="idx1073747037"></a>
<a namE="idx1073747038"></a>
<a Name="idx1073747039"></A>
<a namE="idx1073747040"></a>Microsoft Visual Interdev, which is a very popular tool for ASP development, can be integrated with Python for
Windows. Although it doesn't have any specific knowledge about <tt CLASs="monofont">.py</tt> files, it doesn't expose any problems
when using them.</p>
<P>Using its working environment, you can test and debug Python's active scripts. Another possible option that you have
is to use a free debugger that can be found at <A TArget="_blank" HREF="http://msdn.microsoft.com/scripting">http://msdn.microsoft.com/scripting</a>.
</p>
<p>See <a TARGet="_blank" href="http://starship.python.net/crew/pirx/asp/py_asp.html">http://starship.python.net/crew/pirx/asp/py_asp.html</a> for
more details about using Python with ASP.<a name="idx1073747041"></a>
<a name="idx1073747042"></a>
<a NamE="idx1073747043"></a>
<a nAme="idx1073747044"></a>
<a Name="idx1073747045"></A>
</P>
<H4>
Python Server Pages</H4>
<p>
<i>Python Server Pages</i> is a server-side scripting engine designed along the lines of Microsoft's Active
Server Pages and Sun's Java Server Pages specification. The major difference between ASP and PSP is that PSP is written
in 100% Java and portable to a wide variety of platforms, whereas Web applications written in ASP can be run only on
Microsoft platforms. Python Server Pages uses <a NAME="idx1073747046"></a>
<a naME="idx1073747047"></A>JPython as its scripting language, which seems to be more appropriate for scripting Web sites than the Java
language itself in Java Server Pages.</P>
<p>A major benefit to using PSP is the huge number of add-on modules available for both Python and JPython. You can
access any module that is compatible with JPython from within your PSP application's pages. Because JPython is itself
written in Java, you can access Java packages from your Python Server Pages application as well. For more information,
check out the following:</p>
<p>Python Server Pages</p>
<P>
<A TArget="_blank" href="http://www.ciobriefings.com/psp">http://www.ciobriefings.com/psp</a>
</p>
<p>JRun</p>
<p>JRun is the Java Servlet engine recommended for use with PSP.</p>
<p>
<a targEt="_blank" hRef="http://www.allaire.com/products/jrun/index.cfm">http://www.allaire.com/products/jrun/index.cfm</a>
</P>
<p>JPython</p>
<p>JPython is the scripting language used by PSP.</p>
<P>
<a taRGET="_blank" href="http://www.jpython.org">http://www.jpython.org</A>
<A NAme="idx1073747048"></a>
<a NAME="idx1073747049"></a>
</p>
</foNT>
<P><TABLE width="100%" border=0><TR valign="top"><TD><font size=1 color="#C0C0C0"><br></font></TD><TD align=right><font size=1 color="#C0C0C0">Last updated on 1/30/2002<br>Python Developer's Handbook, © 2002 Sams Publishing</font></TD></TR></TABLE></P>
<TABLE border=0 width="100%" cellspacing=0 cellpadding=0><TR><td align=left width="15%" class="headingsubbarbg"><a href="184.html" title="Creating, Installing, and Running Your Script"><font size="1">< BACK</font></a></td><td align=center width="70%" class="headingsubbarbg"><font size="1"><a href="popanote.asp?pubui=oreilly&bookname=0672319942&snode=185" target="_blank" title="Make a public or private annnotation">Make Note</a> | <a href="185.html" title="Use a Safari bookmark to remember this section">Bookmark</a></font></td><td align=right width="15%" class="headingsubbarbg"><a href="186.html" title="Summary"><font size="1">CONTINUE ></font></a></td></TR></TABLE>
</TD></TR></TABLE>
<br><TABLE width=100% bgcolor=white border=0 cellspacing=0 cellpadding=5><TR><TD><H4 class=Title>Index terms contained in this section</H4>
<font size=2>
<a href="#idx1073746993">Active Scripting</a> <a href="#idx1073747000">2nd</a> <a href="#idx1073747014">3rd</a> <a href="#idx1073747020">4th</a> <a href="#idx1073747025">5th</a> <a href="#idx1073747041">6th</a> <a href="#idx1073747048">7th</a><BR>
<a href="#idx1073746990">Active Server Pages (ASP)</a><BR>
<a href="#idx1073747022">ActiveX scripting</a> <a href="#idx1073747027">2nd</a> <a href="#idx1073747043">3rd</a><BR>
ActiveX<BR>
<a href="#idx1073747024">scripting</a> <a href="#idx1073747029">2nd</a> <a href="#idx1073747045">3rd</a><BR>
<a href="#idx1073746995">alert() function</a><BR>
applications<BR>
<a href="#idx1073747038">Visual Interdev</a><BR>
<a href="#idx1073746991">ASP (Active Server Pages)</a><BR>
<a href="#idx1073747023">ActiveX scripting</a> <a href="#idx1073747028">2nd</a> <a href="#idx1073747044">3rd</a><BR>
data<BR>
<a href="#idx1073747032">sending to screen</a><BR>
debugging<BR>
<a href="#idx1073747011">Active Scripts</a><BR>
executing<BR>
<a href="#idx1073746999">script tags</a><BR>
<a href="#idx1073747007">form name</a><BR>
functions<BR>
<a href="#idx1073746996">alert()</a><BR>
<a href="#idx1073747036">Response_Write()</a><BR>
HTML (Hypertext Markup Language)<BR>
<a href="#idx1073747004">interacting with Python code</a><BR>
HTML pages<BR>
<a href="#idx1073747016">vs. Active Server Pages (ASP)</a><BR>
Hypertext Markup Language (HTML)<BR>
<a href="#idx1073747002">interacting with Python code</a><BR>
<a href="#idx1073746989">IIS (Internet Information Server)</a> <a href="#idx1073747019">2nd</a><BR>
<a href="#idx1073746988">Internet Information Server (IIS)</a> <a href="#idx1073747018">2nd</a><BR>
<a href="#idx1073747046">JPython</a><BR>
names<BR>
<a href="#idx1073747008">form</a><BR>
<a href="#idx1073747006">object_event notation</a><BR>
pages<BR>
HTML<BR>
<a href="#idx1073747017">vs. Active Server Pages (ASPs)</a><BR>
print statements<BR>
<a href="#idx1073747030">sending data to the screen</a><BR>
programming languages<BR>
Hypertext Markup Language (HTML)<BR>
<a href="#idx1073747003">interacting with Python code</a><BR>
<a href="#idx1073747047">JPython</a><BR>
programs<BR>
<a href="#idx1073747039">Visual Interdev</a><BR>
<a href="#idx1073747035">Response_Write() function</a><BR>
screens<BR>
<a href="#idx1073747034">sending data to</a><BR>
<a href="#idx1073747012">script tag</a><BR>
<a href="#idx1073746997">script tags</a><BR>
scripting<BR>
<a href="#idx1073746994">Active</a> <a href="#idx1073747001">2nd</a> <a href="#idx1073747015">3rd</a> <a href="#idx1073747021">4th</a> <a href="#idx1073747026">5th</a> <a href="#idx1073747042">6th</a> <a href="#idx1073747049">7th</a><BR>
security<BR>
<a href="#idx1073746992">Active Scripting</a><BR>
sending<BR>
<a href="#idx1073747033">data to screens</a><BR>
software<BR>
<a href="#idx1073747040">Visual Interdev</a><BR>
statements<BR>
print<BR>
<a href="#idx1073747031">sending data to the screen</a><BR>
tags<BR>
<a href="#idx1073746998">script</a> <a href="#idx1073747013">2nd</a><BR>
<a href="#idx1073747037">Visual Interdev</a><BR>
<a href="#idx1073747005">whitespaces</a><BR>
<a href="#idx1073747009">Windows Scripting Host (WSH)</a><BR>
<a href="#idx1073747010">WSH (Windows Scripting Host)</a><BR>
<BR>
</font></TD></TR></TABLE>
<!--EndOfBrowse-->
</TD></TR></TABLE>
<table width=100% border=0 cellspacing=0 cellpadding=0 bgcolor=#990000><tr><td><p align=center><font size=1 face="verdana,arial,helvetica" color=white>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -