📄 attachaction.java
字号:
package com.wondersgroup.basemodule.attachmentmanage.web.action;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.jspsmart.upload.File;
import com.jspsmart.upload.Files;
import com.jspsmart.upload.SmartUpload;
import com.wondersgroup.basemodule.attachmentmanage.bo.AttachBO;
import com.wondersgroup.basemodule.attachmentmanage.service.AttachService;
import com.wondersgroup.basemodule.holidaymanage.service.HolidayManageService;
import com.wondersgroup.core.BaseAction;
import com.wondersgroup.framework.core.bo.Page;
public class AttachAction extends BaseAction {
private AttachService attachService;
// public void setAttachService(AttachService attachService) {
// this.attachService = attachService;
// }
private static final String FilePath="attach\\file";
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String Action=request.getParameter("action");
attachService=(AttachService)this.getService("attachService", request);
if("upfileed".equals(Action)){
try{
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SmartUpload su=new SmartUpload();
su.initialize(this.getServlet().getServletConfig(),request,response);
su.upload();
Files myfiles=su.getFiles();
for(int i=0;i<myfiles.getCount();i++){
String FileName=""+new Date().getYear()+new Date().getMonth()+new Date().getDate()+(new Date().getTime()+i);
File myfile=myfiles.getFile(i);
String FileNamePath=FilePath+"\\"+FileName+"."+myfile.getFileExt();
if(myfile!=null && !myfile.getFileName().equals("") && myfile.getFileExt()!=null){
myfile.saveAs(FileNamePath);
//save data
String NDate = formatter.format(new Date());
AttachBO attachBO=new AttachBO();
//attachBO.setId(Long.valueOf(FileName).longValue());
attachBO.setOperateTime((java.sql.Timestamp.valueOf(NDate)));
attachBO.setOperator("user");
attachBO.setRemoved(0);
attachBO.setName(myfile.getFileName());
attachBO.setFileType(1);
attachBO.setOrgName(myfile.getFileName());
attachBO.setSaveName(FileName);
attachBO.setSavePath(FilePath);
attachBO.setIsCompress(0);
attachService.saveAttach(attachBO);
}
}
request.setAttribute("reinfo", "上传成功!");
}catch(Exception ex){
ex.printStackTrace();
request.setAttribute("reinfo", "上传失败!");
}
Action="upfile";
}
return mapping.findForward(Action);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -