基于Struts2的通用文件上传实现(二)

四、Action配置

<action name="attachList" class="attachAction">
	<result name="success" type="tiles">attach.list</result>
</action>

<action name="upload" class="attachAction">
	<result name="input" type="tiles">attach.add</result>
	<result name="success" type="tiles">window.close</result>
</action>

<action name="attachDelete" class="attachAction">
	<result name="success" type="redirect">${url}</result>
</action>

<action name="download" class="attachAction">
	<result name="success" type="stream">
		<param name="contentType">application/octet-stream</param>
		<param name="contentDisposition">attachment;filename=${uploadFileName}</param>
		<param name="bufferSize">4096</param>
		<param name="inputName">targetFile</param>
	</result>
</action>

 

五、列表JSP页面源代码

<cjm:toolBar>
	<cjm:toolBarButton title="上传附件" width="80" οnclick="openUploadWindow('upload.action?attach.entityName=%{attach.entityName}&attach.entityId=%{attach.entityId}&attach.refName=%{attach.refName}&attach.path=%{attach.path}&allowTypes=%{allowTypes}&maxSize=%{maxSize}')" imgSrc="images/toolbar/add.gif"/>
	<cjm:toolBarButton title="删除" οnclick="deleteFormRow(document.all['frmAttachList'], 'chk_o_', 'attachDelete.action')" imgSrc="images/toolbar/delete.gif"/>
</cjm:toolBar>
	
<s:form name="frmAttachList">
	<s:hidden name="attach.path" value="%{attach.path}"/>
	<s:hidden name="attach.entityName" value="%{attach.entityName}"/>
	<s:hidden name="attach.entityId" value="%{attach.entityId}"/>
	<s:hidden name="attach.refName" value="%{attach.refName}"/>
	<s:hidden name="allowTypes" value="%{allowTypes}"/>
	<s:hidden name="maxSize" value="%{maxSize}"/>
	
	<table border="0" cellspacing="0" cellpadding="2" class="list" align="center">
		<tr class="top" height="25">
	    	<td width="25"><input type="checkbox" οnclick="checkAll(this)"></td>
	    	<td>附件名称</td>
	    	<td width="100">文件大小</td>
	    	<td width="150">文件类型</td>
	    	<td width="130">创建时间</td>
	    	<td width="50">下载</td>
	  	</tr>
	  	
	  	<s:iterator value="attachList" id="attach" status="st">
	  		<tr <s:if test="#st.odd">class="bg1"</s:if><s:else>class="bg2"</s:else> >
	  			<td align="center"><input type="checkbox" name="chk_o_<s:property value='#st.count'/>" value="<s:property value='#attach.id'/>"></td>
	  			<td align="left"> <s:property value="#attach.name"/></td>
	  			<td align="center"> <s:property value="#attach.fileSize"/> K</td>
	  			<td align="center"> <s:property value="#attach.contentType"/></td>
	  			<td align="center"> <s:date name="#attach.createDate" format="yyyy-MM-dd HH:mm"/></td>
	  			<td align="center"><a href="download.action?attach.id=<s:property value="#attach.id"/>">下载</a></td>
	  		</tr>
	  	</s:iterator>
	</table>
</s:form>

 

六、附件添加JSP页面源代码

<s:form action="upload" name="frmUpload" method="post" enctype="multipart/form-data">
	<s:hidden name="attach.path" value="%{attach.path}"/>
	<s:hidden name="attach.entityName" value="%{attach.entityName}"/>
	<s:hidden name="attach.entityId" value="%{attach.entityId}"/>
	<s:hidden name="attach.refName" value="%{attach.refName}"/>
	<s:hidden name="allowTypes" value="%{allowTypes}"/>
	<s:hidden name="maxSize" value="%{maxSize}"/>
	
	<br>
	<s:file name="upload" label="选择文件" size="55" cdata=" dataType='Require' msg='必填项'"/>
</s:form>

 

七、范例

attachList.action?attach.entityName=Organization&attach.entityId=${org.orgId}&attach.refName=attachment&attach.path=/sim&allowTypes=txt&maxSize=10485760

  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值