?? fileaction.java
字號(hào):
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.richard.struts.action;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.apache.struts.util.ModuleException;
import com.richard.model.TFile;
import com.richard.struts.form.FileActionForm;
/**
* MyEclipse Struts
* Creation date: 08-31-2007
*
* XDoclet definition:
* @struts.action path="/file" name="fileActionForm" parameter="para" scope="request" validate="true"
*/
public class FileAction extends DispatchAction {
com.richard.business.IFileService service;
/*
* Generated Methods
*/
public void setService(com.richard.business.IFileService service) {
this.service = service;
}
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws IOException
*/
public ActionForward upload(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws IOException {
FileActionForm fileActionForm = (FileActionForm) form;// TODO Auto-generated method stub
//fileActionForm.getFileRemark();
// int size=fileActionForm.getFileContent().getFileSize();
// if(size>=100000000){
PrintWriter out=response.getWriter();
out.write("<script type=\"text/javascript\">alert('文件太大了!')</script>");
out.close();
return null;
// }
// TFile tFile=new TFile();
// try {
// tFile.setFileContent(fileActionForm.getFileContent().getFileData());
// } catch (FileNotFoundException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// tFile.setFileName(fileActionForm.getFileContent().getFileName());
// tFile.setFileRemark(fileActionForm.getFileRemark());
// this.service.create(tFile);
// return mapping.findForward("loadAllFile");
}
// FileService fileService = getFileService();
// 11. List fileList = fileService.getAllFile();
// 12. request.setAttribute("fileList",fileList);
// 13. return mapping.findForward("fileListPage");
public ActionForward listAllFile(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
List fileList = this.service.getAllFile();
request.setAttribute("fileList",fileList);
return mapping.findForward("fileListPage");
}
public ActionForward download(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws ModuleException {
//FileActionForm fileForm = (FileActionForm) form;
Long fileId=new Long(request.getParameter("fileId"));
String fileName = this.service.getFileName(fileId);
try{
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition","attachment;" + "filename="+new String(fileName.getBytes(), "ISO-8859-1"));
this.service.write(response.getOutputStream(), fileId);
}catch(Exception e){
throw new ModuleException(e.getMessage());
}
return null;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -