【编者按】:网学网ASP为您提供Asp编码优化技巧8则参考,解决您在asp编码优化技巧8则学习中工作中的难题,参考学习。
ASP(Active Server Page)是Microsoft公司推出的基于PWS(Personal Web Server)&IIS(Internet Information Server)平台的、基于ISAPI(InternetServiceAPI)原理的动态网页开发技术,目前日趋成熟完善。在这里仅就代码优化进行一些简单讨论。HTTP Error 400
400 Bad Request
Due to malformed syntax, the request could not be understood by the server.
The client should not repeat the request without modifications.
解决方法是对生成的URL参数使用ASP内置server对象的URLencode方法进行URL编码,例子如下: <%
URL="xur.asp"
var1="username=" & server.URLencode("xur")
var2="&company=" & server.URLencode("xurstudio")
var3="&phone=" & server.URLencode("021-53854336-186")
response.redirect URL & "?" & var1 & var2 & var3
%>
3、清空对象 <% myDSN="DSN=xur;uid=xur;pwd=xur"
mySQL="select * from authors where AU_ID<100"
set conntemp=server.createobject("adodb.connection")
conntemp.open myDSN
set rstemp=conntemp.execute(mySQL)
if rstemp.eof then
response.write "数据库为空"
response.write mySQL
conntemp.close
set conntemp=nothing
response.end
end if%>
<%do until rstemp.eof %>
<%
rstemp.movenext
loop
rstemp.close
set rstemp=nothing
conntemp.close
set conntemp=nothing
%>
4、使用字符串建立SQL查询 <%mySQL= ""select * "
mySQL= mySQL & "from publishers"
mySQL= mySQL & "where state=''NY''"
response.write mySQL
set rstemp=conntemp.execute(mySQL)
rstemp.close
set rstemp=nothing
%>
5、使用case进行条件选择 <%
FOR i = 1 TO 1000
n = i
Response.Write AddSuffix(n) & "<br>"
NEXT
%>
<%
Function AddSuffix(num)
numpart = RIGHT(num,1)
SELECT CASE numpart
CASE "1"
IF InStr(num,"11") THEN
num = num & "th"
ELSE
num = num & "st"
END IF
CASE "2"
IF InStr(num,"12") THEN
num = num &