raymond.chen 发表于 2013-2-6 09:57:58

基于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"imgSrc="images/toolbar/add.gif"/><cjm:toolBarButton title="删除"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" ></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  
页: [1]
查看完整版本: 基于Struts2的通用文件上传实现(二)