转: Struts 2多文件上传(11)下

3)在配置文件中增加如下配置:

 

< action  name ="doMultipleUploadUsingArray"

            class
="ch11.MultipleFileUploadUsingArrayAction"

            method
="upload" >

            
< result > /ch11/multipleUploadUsingArray-success.jsp </ result >

            
< result  name ="input" > /ch11/multipleUploadUsingArray.jsp </ result >

</ action >

 

4multipleUploadUsingArray-success.jsp的内容如代码11.7所示。

代码11.7  multipleUploadUsingArray-success.jsp内容

 

<% @ page 

    language
="java" 

    contentType
="text/html; charset=UTF-8"

    pageEncoding
="UTF-8"
%>

<% @ taglib prefix="s" uri="/struts-tags"  %>

< html >

< head >

< title > 多个文件上传示例 </ title >

</ head >

< body >

< table  border ="1" >

<!--   使用迭代标签 -->

< s:iterator  value ="dir"  status ="stat" >

< tr >

    
< td > 文件名称 < s:property  value ="%{#stat.index}"   /></ td >

    
< td >< s:property  value ="%{dir[#stat.index]}"   /></ td >

</ tr >    

</ s:iterator >

</ table >

< table  border ="1" >

<!--   使用迭代标签 -->

< s:iterator  value ="uploadContentType"  status ="stat" >

< tr >

    
< td > 文件类型 < s:property  value ="%{#stat.index}"   /></ td >

    
< td >< s:property  value ="%{uploadContentType[#stat.index]}"   /></ td >

</ tr >

</ s:iterator >

</ table >

< table  border ="1" >

<!--   使用迭代标签 -->

< s:iterator  value ="+targetFileName"  status ="stat" >

< tr >

    
< td > 图片 < s:property  value ="%{#stat.index}"   /></ td >

    
< td >< img  src ="<s:property value=" '/bookcode/upload/'+targetFileName[#stat.index]" /> "/> </ td >

</ tr >

</ s:iterator >

</ table >

</ body >

</ html >

 

5)运行该示例,在浏览器中输入http://localhost:8080/bookcode/ch11/multipleUpload UsingArray.jsp,界面如图11.9所示。

 

11.9  使用数组上传多个文件界面

6)在这里,选择3gif文件,单击“上传”按钮,结果如图11.10所示。

 

11.10  使用数组上传多个文件结果

11.2.2  使用List上传多个文件

使用List来上传多个文件同数组基本相同,上传JSP文件和success逻辑视图的JSP文件均不用修改,只是需要相应的Action实现类即可。

猜你喜欢

转载自serenity.iteye.com/blog/1101434