J-Hi Dwz 附件上传类型

J-Hi Dwz 附件上传类型
 1          < dl >
 2              < dt >< hi:text  key ="照片"  entity ="Resume" /></ dt >
 3              < dd >
 4                  < input  type ="hidden"  name ="resume.photo_attachment.id"  value ="${resume.photo_attachment.id}" />
 5                  < input  type ="text"  class ="textInput"  name ="resume.hi_photo_attachment.fileName"  value ="${resume.photo_attachment.fileName}"  readonly ="readonly" />
 6                  < class ="btnAttach"  href ="<hi:url>attachmentLookup.action?lookup=1&from=attachment&saveType=1</hi:url>"  lookupGroup ="resume"  lookupName ="photo_attachment"  width ="560"  height ="300"  title ="<hi:text key=" 附件" />"> < hi:text  key ="附件" /></ a >
 7                  < c:if  test ="${not empty resume.photo_attachment}" >
 8                  < class ="btnView"  href ="attachmentView.action?attachment.id=${resume.photo_attachment.id}"  target ="_blank" >
 9                      < hi:text  key ="查看" />
10                  </ a >
11                  </ c:if >            
12              </ dd >
13          </ dl >

 1  <% @ page language = " java "  contentType = " text/html; charset=utf-8 " %>
 2  <% @ include file = " /includes/main.jsp " %>
 3 
 4  <%
 5  String  attachDesc  =  request.getParameter( " from " );
 6  if  (attachDesc  ==   null  )
 7      attachDesc  =   " attachment " ;
 8  String  attachmentType =  request.getParameter( " saveType " );
 9  if  (attachmentType ==   null  )
10      attachmentType  = " 1 " ;
11  %>
12 
13  < h2  class ="contentTitle" >请选择需要上传的附件 </ h2 >
14  < form  name ="saveForm"  action ="attachmentSave.action?ajax=0"  method ="post"  enctype ="multipart/form-data"  class ="pageForm required-validate"  onsubmit ="return iframeCallback(this, $.bringBack)" >
15 
16 
17  < input  type ="hidden"  name ="attachment.attachDesc"  value ="<%=attachDesc%>"   />
18  < input  type ="hidden"  name ="attachment.attachmentType"  value ="<%=attachmentType%>"   />
19  < input  type ="hidden"  name ="attachment.id"  value ="${attachment.id}" />
20  < input  type ="hidden"  name ="attachment.version"  value ="${attachment.version}" />
21 
22  < div  class ="pageContent" >
23      < div  class ="pageFormContent"  layoutH ="97" >
24          < dl >
25              < dt >附件: </ dt >< dd >< input  type ="file"  name ="image"  class ="required"  size ="30"   /></ dd >
26          </ dl >
27      </ div >
28      < div  class ="formBar" >
29          < ul >
30              < li >< div  class ="buttonActive" >< div  class ="buttonContent" >< button  type ="submit" >上传 </ button ></ div ></ div ></ li >
31              < li >< div  class ="button" >< div  class ="buttonContent" >< button  type ="button"  onclick ="javascript:$.bringBack({id:'-1', fileName:'', attachmentPath:'',attachmentSize:'',imageICO:''})" >< hi:text  key ="重置" /></ button ></ div ></ div ></ li >
32          </ ul >
33      </ div >
34  </ div >
35  </ form >
36 


  1 package org.hi.common.attachment.action.struts;
  2 
  3 import java.io.File;
  4 import java.util.List;
  5 
  6 import org.hi.SpringContextHolder;
  7 import org.hi.framework.HiConfigHolder;
  8 import org.hi.framework.paging.PageInfo;
  9 import org.hi.framework.web.BusinessException;
 10 import org.hi.framework.web.PageInfoUtil;
 11 import org.hi.framework.web.struts.BaseAction;
 12 import org.hi.i18n.util.I18NUtil;
 13 
 14 import org.hi.common.attachment.action.AttachmentPageInfo;
 15 import org.hi.common.attachment.action.cust.FtpUtil;
 16 import org.hi.common.attachment.model.Attachment;
 17 import org.hi.common.attachment.service.AttachmentManager;
 18 
 19 public class AttachmentAction extends BaseAction{
 20     
 21     private Attachment attachment;
 22     private AttachmentPageInfo pageInfo;
 23     private List < Attachment > attachments;
 24     private String orderIndexs;
 25     
 26     private File image;
 27     private String imageFileName;
 28     /**
 29      * 上传文件的文件类型
 30      */
 31     private String imageContentType;
 32     
 33     /**
 34      * 设置上传文件的大小
 35      */
 36     private   String maxSize= HiConfigHolder.getProperty("hi.upload.ftp.maxSize") == null ? "100" : HiConfigHolder.getProperty("hi.upload.ftp.maxSize");
 37     /**
 38      * 新增/修改保存附件
 39      */
 40     public String saveAttachment() throws Exception {
 41         AttachmentManager attachmentMgr = (AttachmentManager)SpringContextHolder.getBean(Attachment.class);
 42         if(super.perExecute(attachment)!= null) return returnCommand();
 43         
 44         if (image != null) {
 45             if (image.length()/1024d/1024d > new Double(maxSize))
 46                 throw new BusinessException(I18NUtil.getStringByParameter("上传文件过大", "Attachment", maxSize));
 47             
 48             String imagePath = "";
 49             if (attachment.getAttachmentType() == 2)
 50                 imagePath = FtpUtil.getFtpUploadClient().saveFileToFTP(image, imageFileName,attachment.getAttachDesc());
 51             else
 52                 imagePath =  FtpUtil.getOSFileClient().saveFile(image, imageFileName,attachment.getAttachDesc());
 53             
 54             attachment.setAttachmentPath(imagePath);
 55             attachment.setFileSize( image.length()/1024d ); 
 56             attachment.setFileType(imageContentType);
 57             attachment.setFileName(imageFileName);
 58             attachmentMgr.saveObject(attachment);
 59         }
 60         
 61     
 62         super.postExecute(attachment);
 63         return returnCommand();
 64     }
 65     
 66     
 67     /**
 68      * 删除附件
 69      */
 70     public String removeAttachment() throws Exception {
 71         AttachmentManager attachmentMgr = (AttachmentManager)SpringContextHolder.getBean(Attachment.class);
 72         attachmentMgr.removeAttachmentById(attachment.getId());
 73         return returnCommand();
 74     }
 75     
 76     /**
 77      * 删除指定的某些附件
 78      */
 79     public String removeAllAttachment() throws Exception {
 80         AttachmentManager attachmentMgr = (AttachmentManager)SpringContextHolder.getBean(Attachment.class);
 81         if (orderIndexs != null && orderIndexs.length()> 0 )
 82         {
 83             String[] ids= orderIndexs.split(",");
 84             for( int i=0; i < ids .length; i++)
 85              {
 86                  if (ids[i].length() >0)
 87                 {
 88                 Integer attachmentid = new Integer( ids[i] );
 89                 attachmentMgr.removeAttachmentById(attachmentid);
 90                 }
 91             }
 92         }
 93         
 94         return returnCommand();
 95     }
 96     
 97     /**
 98      *查看附件
 99      */
100     public String viewAttachment() throws Exception {
101         AttachmentManager attachmentMgr = (AttachmentManager)SpringContextHolder.getBean(Attachment.class);
102         attachment = attachmentMgr.getAttachmentById(attachment.getId());
103         return returnCommand();
104     }
105     
106     /**
107      * 附件列表
108      */
109     public String attachmentList() throws Exception {
110         AttachmentManager attachmentMgr = (AttachmentManager)SpringContextHolder.getBean(Attachment.class);
111         pageInfo = pageInfo == null ? new AttachmentPageInfo() : pageInfo;
112         PageInfo sarchPageInfo = PageInfoUtil.populate(pageInfo, this);
113         
114         attachments = attachmentMgr.getAttachmentList(sarchPageInfo);
115         
116         return returnCommand();    
117     }
118     
119     
120     
121     
122     public Attachment getAttachment() {
123         return attachment;
124     }
125 
126     public void setAttachment(Attachment attachment) {
127         this.attachment = attachment;
128     }
129     
130     public List < Attachment > getAttachments() {
131         return attachments;
132     }
133 
134     public void setAttachments(List < Attachment > attachments) {
135         this.attachments = attachments;
136     }
137 
138     public AttachmentPageInfo getPageInfo() {
139         return pageInfo;
140     }
141 
142     public void setPageInfo(AttachmentPageInfo pageInfo) {
143         this.pageInfo = pageInfo;
144     }    
145     
146     public String getOrderIndexs() {
147         return orderIndexs;
148     }
149 
150     public void setOrderIndexs(String orderIndexs) {
151         this.orderIndexs = orderIndexs;
152     }
153 
154 
155     public File getImage() {
156         return image;
157     }
158 
159 
160     public void setImage(File image) {
161         this.image = image;
162     }
163 
164 
165     public String getImageFileName() {
166         return imageFileName;
167     }
168 
169 
170     public void setImageFileName(String imageFileName) {
171         this.imageFileName = imageFileName;
172     }
173 
174 
175     public String getImageContentType() {
176         return imageContentType;
177     }
178 
179 
180     public void setImageContentType(String imageContentType) {
181         this.imageContentType = imageContentType;
182     }
183 
184 
185     public String getMaxSize() {
186         return maxSize;
187     }
188 
189 
190     public void setMaxSize(String maxSize) {
191         this.maxSize = maxSize;
192     }
193     
194     
195     
196 }
197 

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE struts PUBLIC
 3     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
 4     "http://struts.apache.org/dtds/struts-2.0.dtd">
 5 <struts>
 6     < package name="attachment"  extends="hi" >
 7         <!-- ============= 附件对应的AttachmentAction============ --> 
 8 
 9         
10         <action name="attachmentSave"
11              class="org.hi.common.attachment.action.struts.AttachmentAction" method="saveAttachment">
12             <result name="success" >/attachment/AttachmentBrightBack.jsp</result>
13             <interceptor-ref name="modelStackUpload" />
14         </action>
15                     
16         <action name="attachmentView"
17              class="org.hi.common.attachment.action.struts.AttachmentViewAction">
18             <result name="success" type="stream">
19             <param name="inputName">inputStream</param>
20             <param name="contentType">${contentType}</param>
21             <param name="contentDisposition">filename="${fileName}"</param>
22             </result>
23             <interceptor-ref name="modelParamsStack" />
24         </action>        
25         
26         
27           <action name="attachmentLookup"
28              class="org.hi.common.attachment.action.struts.AttachmentAction" method="attachmentList">
29             <result name="success">/attachment/AttachmentList.jsp</result>
30             <interceptor-ref name="modelParamsStack" />
31         </action>        
32 
33 </ package>
34 </struts>

你可能感兴趣的:(J-Hi Dwz 附件上传类型)