ASP网页设计代码分别举措
优点:简单易学、开发速度快、有很多年“历史”,能找到非常多别人做好的程序来用、配合activeX功能强大,很多php做不到的asp+activeX能做到,例如银行安全控件代码分别index.asp
-----------------------------------------------------------------------
<!--#includefile="templateclass.asp"-->
<%
Thisisthecodeusedtoloadanddisplaythetemplate.
Seehowcleanitis!!!:)
subgo()
dimoTemplate
setoTemplate=newtemplate
withoTemplate
.usetemplate("message.tpl")
.tag("date")=Date()
.tag("self")="<divstyle=background:#dddddd>"&.gettemplate("message.tpl",true)&"</div>"
.tag("aspcode")=.gettemplate("index.asp",false)
.tag("howtouse")=.gettemplate("howtouse.tpl",false)
.display()
endwith
setoTemplate=nothing
endsub
go()
%>
templateclass.asp
------------------------------------------------------------------------
<%
Thisisthetemplateobject.Itallowsthecreation,reading
andeditingoftemplatesontheserver.
CREATEDBY:ChristopherBrown-Floyd
DATE:November3,1999
classtemplate
Thisvariablestoresthetemplate
privatemytemplateasstring
Thismethodgetsatemplatefromtheserverandreturns
thewholefileasastring.
publicfunctiongettemplate(pathfilename,encodetohtml)asstring
dimoFSOasobject
dimoTemplateasobject
dimtemptemplateasstring
Opentypeforthetemplate(read-only)
constforreading=1,boolcreatefile=false
ifIsNull(encodetohtml)orencodetohtml=""orencodetohtml=falsethen
encodetohtml=false
else
encodetohtml=true
endif
onerrorresumenext
Createfilesystemobject
setoFSO=server.createobject("scripting.filesystemobject")
Createtemplateobject
setoTemplate=oFSO.opentextfile(server.mappath(pathfilename),forreading,boolcreatefile)
iferr0then
err.clear
exitfunction
endif
Getthewholefileasastring
temptemplate=oTemplate.readall
EncodetemplatetoHTML?
ifencodetohtmlthen
gettemplate=tohtml(temptemplate)
else
gettemplate=temptemplate
endif
Closethetemplate
oTemplate.close
Freetheserverresources
setoTemplate=nothing
setoFSO=nothing
endfunction
Thisproceduregetsandstoresatemplate
publicsubusetemplate(pathfilename)
thistemplate=gettemplate(pathfilename,false)
endsub
Thispropertyreplacestagswiththeuserstemplate
publicpropertylettag(tagname,userstring)
dimld,rdasstring
dimtemptagasstring
dimtagstart,tagendasinteger
ld="<!--"
rd="-->"
tagstart=1
dowhiletagstart>0andtagstart<len(thistemplate)
tagstart=instr(tagstart,thistemplate,ld)
iftagstart>0then
tagend=instr(tagstart,thistemplate,rd)
iftagend>(tagstart+3)then
temptag=mid(thistemplate,tagstart+4,tagend-(tagstart+4))
if(trim(temptag)=tagname)or(temptag=tagname)then
ifIsNull(userstring)then
thistemplate=replace(thistemplate,ld&temptag&rd,"")
else
thistemplate=replace(thistemplate,ld&temptag&rd,userstring)
endif
exitdo
else
tagstart=tagstart+4
endif
endif
endif
loop
endproperty
publicsubremoveTags()
dimld,rdasstring
dimtemptagasstring
dimtagstart,tagendasinteger
ld="<!--"
rd="-->"
tagstart=1
dowhiletagstart>0andtagstart<len(thistemplate)
tagstart=instr(tagstart,thistemplate,ld)
iftagstart>0then
tagend=instr(tagstart,thistemplate,rd)
iftagend>(tagstart+3)then
temptag=mid(thistemplate,tagstart+4,tagend-(tagstart+4))
thistemplate=replace(thistemplate,ld&temptag&rd,"")
tagstart=tagend
endif
endif
loop
endsub
Thispropertyallowstheusertoassignthecurrenttemplate
publicpropertyletthistemplate(template_as_string)
ifvartype(template_as_string)=vbstring_
orvartype(template_as_string)=vbnullthen
mytemplate=template_as_string
endif
endproperty
Thispropertyreturnsthecurrenttemplate
publicpropertygetthistemplate()asstring
thistemplate=mytemplate
endproperty
Thissubroutinedisplaysthecurrenttemplate
publicsubdisplay()
response.writethistemplate
endsub
ThissubroutineencodesthecurrenttemplatetoHTML
publicsubhtmlencode()
tohtml(thistemplate)
endsub
Thisproceduresavesthecurrenttemplatetotheserver
publicsubsaveas(pathfilename)
dimoFSOasobject
dimoTemplate,oBackupasobject
dimstrTruePathasstring
Opentypeforthetemplate(read-only)
constforreading=1,forwriting=2,boolcreatefile=true
onerrorresumenext
Createfilesystemobject
setoFSO=server.createobject("scripting.filesystemobject")
Createtemplateobject
strTruePath=server.mappath(pathfilename)
ifoFSO.fileexists(strTruePath)then
oFSO.copyfilestrTruePath,strTruePath&".bak",true
endif
setoTemplate=oFSO.opentextfile(strTruePath,forwriting,boolcreatefile)
iferr0then
err.clear
exitsub
endif
Writethewholetemplatetotheserver
oTemplate.writethistemplate
Closethetemplate
oTemplate.close
Freetheserverresources
setoTemplate=nothing
setoFSO=nothing
endsub
Thisfunctionencodestexttohtml
privatefunctiontohtml(temptemplate)
temptemplate=replace(temptemplate,"<","<")
temptemplate=replace(temptemplate,"","")
temptemplate=replace(temptemplate,vbcrlf,"<br/>")
tohtml=temptemplate
endfunction
Thisprocedureclearsthevariablethatthecurrenttemplate
isstoredinwhentheobjectiscreated.
privatesubclass_initialize()
mytemplate=""
endsub
Thisprocedureclearsthevariablethatthecurrenttemplate
isstoredinwhentheobjectisterminated.
privatesubclass_terminate()
setmytemplate=nothing
endsub
endclass
%>
howtouse.tpl
------------------------------------------------------------------------
<h3>Objectsproperties:</h3>
<divstyle="background:#dddddd"><p><b>thistemplate</b>=<i>String</i>
Loadsadynamicallybuilttemplateintothetemplateobject.Usethismethod
whenthereisntafiletoreadfrom.</p></div>
<h3>Objectsprocedures:</h3>
<divstyle="background:#dddddd"><p><b>tag(<i>tagnameasstring</i>)</b>=<i>String</i>
Replacesalloccurrencesofatagwithinthecurrenttemplatewiththespecifiedstring.</p>
<p><i>variable</i>=<b>gettemplate(<i>pathasstring</i>,<i>asboolean</i>)</b>
Returnsthetemplatefromthespecifiedpath;however,itisntloadedintotheobject.</p></div>
<h3>Objectsmethods:</h3>
<divstyle="background:#dddddd"><p><b>usetemplate(<i>pathasstring</i>)</b>
Loadsthetemplatefromthespecifiedpathintotheobject.</p>
<p><b>htmlencode()</b>
EncodesthecurrenttemplateloadedintoHTML.</p>
<p><b>display()</b>
Writesthecurrenttemplatetotheusersbrowser.</p>
<p><b>removetags()</b>
Removesalltagsthathaventbeenreplaced.</p>
<p><b>saveas(<i>pathashtml</i>)</b>
Savesthecurrenttemplatetothespecifiedpath.Usethismethodwhenyou
wanttosavethechangesmadetothetemplate.
NOTE:Ifafileofthesamenameexistsatthespecifiedpath,".bak"willbe
addedtotheendofitsname;thus"myfile.tpl"wouldbecome"myfile.tpl.bak".</p></div>
</div>
message.tpl
------------------------------------------------------------------------
<html>
<body>
<pre>
Thisisanexampleofhowtousemytemplateclass.
Dynamicdataforyourtemplatecancomefromanywhere.
Itcancomefromabuilt-inASPfunction:<!--date-->
Itcancomefromafile:
<!--self-->
YoucanevenuseitasanonlinesourceeditingtoolforyourASPcode:
<form><textareacols="80"rows="30"><!--aspcode--></textarea></form>
<!--howtouse-->
NOTE:TemplatescanthaveanyASPcodeinthem.ItllonlyprocessHTML.
Thisisgoodpractice,becauseitproducescleanercodeandHTML.
</pre>
</body>
</html>
但愿能对你有所匡助!
ASP最大的缺点在于网络的安全性和可靠性,企业将经营数据放在开放的平台上,最大的担忧就是如何保证这些数据不被其他人破坏。 交流是必要的,不管是生活还是学习我们都要试着去交流,通过交流我们可以学到很多我们自己本身所没有的知识,可以分享别人的经验甚至经历。 我想问如何掌握学习节奏(先学什么再学什么)最好详细点? 运用ASP可将VBscript、javascript等脚本语言嵌入到HTML中,便可快速完成网站的应用程序,无需编译,可在服务器端直接执行。容易编写,使用普通的文本编辑器编写,如记事本就可以完成。由脚本在服务器上而不是客户端运行,ASP所使用的脚本语言都在服务端上运行。 Session:这个存储跟客户端会话过程的数据,默认20分钟失效 如何更好的使自己的东西看上去很不错等等。其实这些都不是问题的实质,我们可以在实践中不断提升自己,不断充实自己。 我就感觉到ASP和一些常用的数据库编程以及软件工程方面的思想是非常重要的。我现在也在尝试自己做网页,这其中就用到了ASP,我想它的作用是可想而知的。 另外因为asp需要使用组件,所以了解一点组件的知识(ADODB也是组件) ASP.Net摆脱了以前ASP使用脚本语言来编程的缺点,理论上可以使用任何编程语言包括C++,VB,JS等等,当然,最合适的编程语言还是MS为.NetFrmaework专门推出的C(读csharp),它可以看作是VC和Java的混合体吧。
页:
[1]