六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 103|回复: 0

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

[复制链接]

升级  54%

33

主题

33

主题

33

主题

秀才

Rank: 2

积分
131
 楼主| 发表于 2013-2-6 09:57:58 | 显示全部楼层 |阅读模式
四、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  
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表