12-3 如?使用 ASP ??HTML

ASP ɮ׳q`H asp ɦWAO@ӤrɡAF]t򥻪 HTML аO~A٥iH]t ASP {XCASP {XOH <% ... %> аOөM HTML ϤAAoıΤݭnDɮ׬OHuaspvɦWAN|M ASP {Xð椧CƹWAASP аO <% ... %> O@²gAYnϥΤPyANϥΧ㪺ܤ覡CҦpAYnϥ JScript Ӽg ASPANϥΤUC榡G
<script language=jscript runat=server>
	JScript {X
</script>
䤤nSO`NOurunat=servervAYS[Wo@yAAN|o@q{XAӱNe^ΤݡAGoq{X|ܦѥΤݪsӰANjSFI

Hint
ƹWA]t ASP {XAiH asp ɦWAҦpAAiH hi ASP ɦWAunb IIS Ai]wYiC

ϥΤWz覡AAiHb@ ASP VXϥΤPyAunA[W language ݩʧYiCYnb@ ASP ϥ JScriptA@ӧ²檺@kO]wӺ language ݩʡAunbĤ@C[JUz{XYiG

<%@ language=jscript %>
b <% ... %> ]{XA|QO JScript {XAåѦAIs JScript ĶӰ椧C

Hint
FקKܵ{yұaӪxZAbҵ{Aڭ̨᪺ asp {dҡA|ɶqH JScript ӼgC

YnLXܼ x ȡAiΤUCؤkG

  1. <%Response.Write(x)%>
  2. <%=x%>
䤤 Response O ASP تAWrite() hO䤤@ؤkCѩ Response.Write `QΨA]NoiXĤGا²KCL覡C |ҨӻAYnb HTML LXuHello World!vAUCƺؤ覡iFP˪ĪGG
  1. <%Response.Write("Hello World!")%>
  2. <%="Hello World!"%>
  3. <%x = "Hello World!"%><%Response.Write(x)%>
  4. <%x = "Hello World!"%><%=x%>
bUCdҤAڭ̥HWzkLX|CuHello World!vG

Example]hello01.asp^G

WzdҪlɦpUG

lɡ]hello01.asp^G]ǦϰUYi^
<%@language=jscript%>

<%title="ASP LXuHello World!v|ؤk"%>
<!--#include file="head.inc"-->
<hr>

Four methods to print "Hello World!" in server-side VBScript:
<p>
<%Response.Write("Hello World!")%><br> 
<%="Hello World!"%><br>
<%x = "Hello World!"%><%Response.Write(x)%><br>
<%x = "Hello World!"%><%=x%><br>

<hr>
<!--#include file="foot.inc"-->

bѪ䥦 ASP dҤAڭ̳ϥ head.inc ӥNۦP}lAèϥ u<!--#include file="head.inc"-->v覡ӱN head.inc ɮץ]tiӦdҺChead.inc epUG

lɡ]head.inc^G]ǦϰUYi^
<html>
<head>
	<title><%=title%></title>
	<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=big5">
	<style>
		td {font-family: "з", "helvetica,arial", "Tahoma"}
		A:link {text-decoration: none}
		A:hover {text-decoration: underline}
	</style>
</head>
<body>
<h2 align=center><%=title%></h2>

P˪Afoot.inc ONۦPAڭ̨ϥ u<!--#include file="foot.inc"-->v覡ӱN foot.inc ɮץ]tiӡAfoot.inc epUG

lɡ]foot.inc^G]ǦϰUYi^
<script>function viewSource() {window.location="view-source:"+window.location} </script>
<%
fso=Server.CreateObject("Scripting.FileSystemObject");
parentDir=Request.ServerVariables("URL")+"";
parentDir=fso.GetParentFolderName(parentDir);
if (parentDir.indexOf("example")!=parentDir.length-7){
//	Response.Write(parentDir+"<br>");
	parentDir=fso.GetParentFolderName(parentDir);
}
showCodePage=parentDir+"/showcode.asp";		// showCodePage="/jsBook/asp/example/showcode.asp"
%>
View sourceG
[<a target=_blank href="<%=showCodePage%>?source=<%=Request.ServerVariables("PATH_INFO")%>">Server-side script</a>]
[Client-side script (ctrl+u)]
<br>^u<a href="/jang/books/asp">JScript {]pPΡGA</a>v</b>
</html>

Hint
ϥ <!--#include file="fileName"--> ӥ[Jɮ fileName 覡٬ Sever-Side IncludeA² SSIAN|b᭱ԲӪC

Ynϥ ASP LXƦCuHello World!vóvWjrAiUCdҡG

Example]hello02.asp^G

WzdҪlɦpUG

lɡ]hello02.asp^G]ǦϰUYi^
<%@language=jscript%>
<%title="Q ASP LXjpPuHello World!v"%>
<!--#include file="head.inc"-->
<hr>

<% for (i=1; i<=5; i++) {%>
	<font size=<%=i%>> Hello World! </font><br>
<%}%>

<hr>
<!--#include file="foot.inc"-->

Hint
`ٽgTAb򪺵{XC̡ANAܳo ASP dҺҥΨ쪺зYPɧAӥHu...vNC

bWzdҤ for jAڭ̥eϥΤF ASP {XM HTML lXAoإe覡YϥΤӦhA|y{XIJvCA]ڭ̤]iHNgO ASP {XAe{ĪGۦPAlXpUG

lɡ]hello03.asp^G]ǦϰUYi^
<%@language=jscript%>
<%title="Q ASP LXjpPuHello World!v"%>
<!--#include file="head.inc"-->
<hr>

<%
for (i=1; i<=5; i++){
	Response.Write("<font size=" + i + "> Hello World! </font><br>");
}
%>

<hr>
<!--#include file="foot.inc"-->

b Client ScriptA<script> Ҫw]yY JavaScript JScriptCӦb Server ScriptA<script runat=server> Ҫw]yY VBScriptCizpUG


Client-side Scripts Server-side Scripts
JavaScript
(JScript)
<script>...</script>
<script runat=server language=jscript>...</script>
VBScript <script language=vbscript>
<% ... %>
<script runat=server>...</script>

~AJScript M VBScript UCPBAbg ASP {XɡAnSOpߡG

FKA󥻤p`UӽdҡAڭ̤]Ѭ VBScript {XAҦp hello01.asp Oϥ JavaScript ASP Ah hello01_vbs.asp hOϥ VBScript ASP AШ̦C
JScript {]pPΡGΩAݪ ASP