ASP常見問題及解答(10)

來源:互聯網
上載者:User
解答|問題 1.關於<table>折行:
<table style="TABLE-LAYOUT: fixed" width="200" border="0" cellspacing="0" cellpadding="7" bgcolor="#f7f7f7">
<tr>
<td style="LEFT: 0px; WIDTH: 100%; WORD-WRAP: break-word">
dffadfdaqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqsfdffadfdasfdffadfdasfdffadfdasfdffadfdasfdffadfdasfdffadfdasfdffadfdasfdffadfdasfdffadfdasf
</font></td>
</tr>
</table>

重點是"WORD-WRAP: break-word"把它去掉再看看就知道了.



2.批量錄入在資料庫的應用中比較廣泛的,關於批量錄入的方法也有好多種。
下面我就結合我實際中的應用,談一下兒我是怎麼實現的。
主要用到的是form的集合的概念,通過迴圈取的所有的集合內資料。
考慮到大家看著方便,我把它整合到了一個頁面。
下面是具體的代碼:
batchInput.asp
<%
'#####################################
'File Function:批量錄入資料
'Author:Myhon
'Date:2003-8-19
'#####################################

'向資料庫寫入資料
SUB writeData()
dim recCnt,i
dim fieldName1,fieldName2,fieldName3
dim conn
dim sqlStr,connStr
connStr="Provider=SQLOLEDB.1;Initial Catalog=myDatabase;Data Source=myhon;User Id=sa;PASSWORD="
set conn=Server.CreateObject("ADODB.Connection")
conn.open connStr '建立資料庫連接

recCnt=request.form("stu_num").count '取得共有多少條記錄
'批量錄入資料
for i=1 to recCnt
fieldName1=trim(request.form("fieldName1")(i))
fieldName2=trim(request.form("fieldName2")(i))
fieldName3=trim(request.form("fieldName3")(i))
sqlStr="insert into myTable(fieldName1,fieldName2,fieldName3) values('"
sqlStr=sqlStr & fieldName1 & "','"
sqlStr=sqlStr & fieldName2 & "','"
sqlStr=sqlStr & fieldName3 & "')"
'response.write sqlStr
conn.execute(sqlStr)
next
END SUB

'顯示成批錄入的介面
SUB InputData()
dim recCnt,i
%>
<form name="bathInputData" action="" method="post">
<%
recCnt=cint(request.form("recCnt"))
for i=1 to recCnt
%>
<input type="text" name="fieldName1">
<input type="text" name="fieldName2">
<input type="text" name="fieldName3">
<%
next
%>
<br/>
<input type="submit" name="action" value="提交">
</form>
<%
END SUB

'指定要批量錄入多少條記錄
SUB assignHowMuch()
%>

<!------指定要錄入多少條記錄-------------->
<form name="form1" action="" method="post">
您要錄入的記錄的條數:<input type="text" name="recCnt">
<input type="submit" name="action" value="下一步>>">
</form>
<%
END SUB

if request.form("action")="下一步>>" then
Call InputData() '顯示成批錄入介面
elseif request.form("action")="提交" then Call writeData() '向資料庫批量寫入資料
else
Call assignHowMuch() '顯示指定錄入多少條記錄的介面
end if

%>



3.以動感下載系統為例:

開啟檔案 SoftDown.Asp 在:
if request.QueryString("ID")="" then
response.write "不能串連或者沒有指定下載軟體"
response.end
end if
的上面或者是下面加上下列代碼

dim strReferer,domain,splDomain,isHttp
isHttp=false

'本站下載系統網址列表,不要帶上http://
domain="sron.net,61.156.14.223,61.156.14.227"

splDomain=split(domain,",")
strReferer=Request.ServerVariables("HTTP_REFERER")
for iii = 0 to ubound(splDomain)
if instr(strReferer,trim(splDomain(iii)))>0 then isHttp=True
next
if isnull(strReferer) or isHttp=false then
Response.Write "下載連結來自其他網站,這是不允許的,<a href=""./"">請進入本站頁面後再進行下載。</a>"
CloseDatabase
response.end
end if

本站下載系統網址列表 就是訪問你下載頻道網址裡的網域名稱,比如你的下載頻道可以用多個網址來訪問,所以這裡用逗號隔開.



4.無法寫入cookie的常見問題
1.確定你的response.cookie代碼在第一個<html>之前
2.設定cookies的到期日response.cookie("cookiename").expires = expiresdate;

設定cookie的請求指定路徑:
就是說你的cookie寫入後,指定路徑中的頁面才有權得到這個cookie
例如:指定路徑response.cookie("cookiename").path = "http://www.domain.com/path"
那麼只有path目錄中的頁面才能得到request.cookie("cookiename")



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.