一、準(zhǔn)備
1
、確保有
struts
運(yùn)行環(huán)境;
2
、下載
newxy1.04.zip
或更高版。解壓,將
newxy1.04.jar
或更高版類庫(kù)拷到
WEB-INF/lib
下,將
newxy-html.tld
、
newxy-logic.tld
、
newxy-bean.tld
三個(gè)標(biāo)簽定義文件拷到
WEB-INF/
目錄下,將
newxy.properties
文件拷到
WEB-INF/classes
下,并根據(jù)需要進(jìn)行設(shè)置;
3
、建一
jsp
文件,如
upload.jsp
二、
jsp
文件?
???????????????????????? <%@ page contentType="text/html; charset=GBK" %>
????????????????? ?????? <%@ tagliburi="/WEB-INF/newxy-html.tld" prefix="nhtml"%>
???????????????????????? <%@ tagliburi="/WEB-INF/newxy-logic.tld" prefix="nlogic"%>
<nlogic:action1 id="act1" formName="fileForm"/>
<nhtml:form action="" formName="fileForm" enctype="multipart/form-data">
?
數(shù)據(jù)庫(kù)表名:
<input type="text" name="_table" size="40"/><br />
?
說(shuō)明:
<input type="text" name="explain" size="40"/><br />
?
不大于
1024K
:
<nhtml:file property="field1" size="40" maxSize="1024"/><br />
?
不大于
1024K
:
<nhtml:file property="field2" size="40" maxSize="1024"/><br />
</nhtml:form>
<nhtml:buttonactionId="act1" method="update"/>
?
三、說(shuō)明
上傳多個(gè)文件只需加入多個(gè)<nhtml:file />標(biāo)簽,可以不寫
java
代碼。
1
、
_table
為保留屬性,其值是數(shù)據(jù)庫(kù)表名。
2
、
newxy
(
新坐標(biāo)
)
實(shí)現(xiàn)文件上傳至數(shù)據(jù)庫(kù),可以同時(shí)保存文件名、文件類型、大小、擴(kuò)展名等信息。
標(biāo)簽<nhtml:file />詳解
文件名:
|
上傳的文件名保存到某字段中,保存文件名的字段名由
<nhtml:file/>
標(biāo)簽
fileNameField
元素值指定。
|
文件大小:
|
上傳的文件大小保存到某字段中,保存文件大小的字段名由
<nhtml:file/>
標(biāo)簽
fileSizeField
元素值指定。本例上傳文件不大于
1024K
|
文件類型:
|
上傳的文件類型保存到某字段中,保存文件類型的字段名由
<nhtml:file/>
標(biāo)簽
fileTypeField
元素值指定。
|
文件擴(kuò)展名:
|
上傳的文件擴(kuò)展名保存到某字段中,保存文件擴(kuò)展名的字段名由
<nhtml:file/>
標(biāo)簽
fileExtendNameField
元素值指定。
|
限制類型:
|
上傳文件的限制類型由
<nhtml:file/>
標(biāo)簽
fileLimit
元素值指定。如
fileLimit
="jsp"
,只能上傳
jsp
文件。本例不限制。
|
3
、
property
屬性值是保存文件內(nèi)容的字段名。
4
、上傳文件大小由
maxSize
屬性值確定,本例可同時(shí)上傳二個(gè)文件,上傳文件不大于
1024K
。理論上同時(shí)上傳文件數(shù)量不限,上傳成功與否會(huì)提示給用戶。如果
maxSize
為空,最大值不大于
struts
設(shè)置的最大值,默認(rèn)最大值為
250M
。
5
、標(biāo)簽
<nhtml:form action="" formName="fileForm" />
的
action
屬性是空值,表明以當(dāng)前路徑作為
頁(yè)面表單的
action
值。
formName
屬性值與標(biāo)簽
<nlogic:action1 id="act1" formName="fileForm"/>
的
formName
屬性值相同。
6
、標(biāo)簽
<nlogic:action1 id="act1" formName="fileForm"/>
產(chǎn)生靜態(tài)頁(yè)面的
javascript
函數(shù):
act1
Update(
...){...}
。點(diǎn)擊“文件上傳”按鈕將調(diào)用這個(gè)函數(shù)。結(jié)果是將數(shù)據(jù)提交上來(lái)由標(biāo)簽
nlogic:action1 id="act1" formName="fileForm"/>
來(lái)處理,將文件內(nèi)容寫到數(shù)據(jù)庫(kù)的字段中。
7
、標(biāo)簽
<nhtml:buttonactionId="act1" method="update" value=”
文件上傳
”
/>
的
onclick
事件調(diào)用
act1
Update()
方法。?
??????? 另見(jiàn)《newxy新坐標(biāo)多文件上傳(上傳至文件夾)》
????? 新坐標(biāo)技術(shù)網(wǎng)站:http://www.newxy.net
posted on 2006-08-21 18:23
newxy新坐標(biāo) 閱讀(416)
評(píng)論(0) 編輯 收藏