超簡單的struts檔案上傳

2021-04-24 03:01:05 字數 2384 閱讀 8684

struts檔案上傳1.

頁面配置

<formaction="upload.do"method="post"enctype="multipart/form-data">

<inputtype="text"name="title"><br>

檔案:<inputtype="file"name="file"><br>

<inputtype="submit"value="提交">

form>

2.

actionform中使用formfile來接受上傳檔案,**如下:

publicclassuploadformextendsactionform

publicvoidsetfile(formfile file)

}

3.

action中使用formfile來接收上傳檔案,**如下:

struts-config.xml

中的配置

配置form:

<

form-bean

name

="uploadform"

type

="com.zsw.struts.form.uploadform"

/>

配置action:

<action

attribute="uploadform"

name="uploadform"

path="/upload"

scope="request"

type="com.zsw.struts.action.uploadaction">

<forwardname="success"path="/upload_success.jsp"/>

<forwardname="error"path="/upload_error.jsp"/>

action>

struts超簡單入門( )

作為最流行的web framework,struts的入門可能算是比較麻煩了,本人花費了一整天的時間才算將他初步執行成功,現將成果整理如下 例子的需求 1 允許使用者輸入乙個名字,提交後返回 hello 輸出形式為hello 字串 2 當使用者沒有輸入名字時,返回乙個錯誤提示 3 當使用者輸入的名字...

struts超簡單入門( )

例子的需求 1 允許使用者輸入乙個名字,提交後返回 hello 輸出形式為hello 字串 2 當使用者沒有輸入名字時,返回乙個錯誤提示 3 當使用者輸入的名字帶 符號時,提示錯誤資訊,即不允許輸入含有 符號的名字 例子的執行環境 windows2000 jdk1.4.2 tomcat5.0 str...

struts的檔案上傳

前台頁面 在struts中設定 寫action action的屬性值 privatefile photo privatestring photofilename privatestring title action的方法 publicstring errorexe os.flush 重新整理快取 輸...