?? uploadfileaction.java
字號:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.lxoa.msg.web.action;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;
import com.lxoa.common.action.BaseAppDispatchAction;
import com.lxoa.msg.web.form.UploadFileForm;
/**
* MyEclipse Struts Creation date: 08-31-2008
*
* XDoclet definition:
*
* @struts.action path="/uploadFile" name="uploadFileForm"
* input="/msg/uploadFile.jsp" parameter="method" scope="request"
* validate="true"
*/
public class UploadFileAction extends BaseAppDispatchAction {
/*
* Generated Methods
*/
/**
* Method execute
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward upload(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
UploadFileForm uploadFileForm = (UploadFileForm) form;// TODO
// Auto-generated
// method stub
FormFile file = uploadFileForm.getFile();
// If no file was uploaded (e.g. first form load), then display View
if (file == null || file.getFileName().equals("")) {
return mapping.findForward("index");
}
// Get the name and file size
String fname = file.getFileName();
String size = Integer.toString(file.getFileSize()) + " bytes";
int len=file.getFileSize();
byte[] buffer=new byte[len];
InputStream streamIn = file.getInputStream();
streamIn.read(buffer, 0, len);
uploadFileForm.setBuffer(buffer);
uploadFileForm.setFname(fname);
uploadFileForm.setSize(size);
HttpSession session = request.getSession();
List<UploadFileForm> fileList = (List<UploadFileForm>) session
.getAttribute("FileList");
if (fileList == null) {
fileList = new ArrayList<UploadFileForm>();
}
// List fileList=(List)new java.util.ArrayList();
try {
fileList.add(uploadFileForm);
} catch (Exception e) {
e.printStackTrace();
}
session.setAttribute("FileList", fileList);
return mapping.findForward("index");
}
public ActionForward unspecified(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// List<UploadFileForm> fileList = new ArrayList<UploadFileForm>();
// request.setAttribute("FileList",fileList);
// System.out.println("nihao");
return mapping.findForward("index");
}
public ActionForward choseR(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// List<UploadFileForm> fileList = new ArrayList<UploadFileForm>();
// request.setAttribute("FileList",fileList);
System.out.println("chjose");
return mapping.findForward("choseRindex");
}
public ActionForward delList(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String index = (String) request.getParameter("index");
HttpSession session = request.getSession();
List<UploadFileForm> fileList = (List<UploadFileForm>) session
.getAttribute("FileList");
fileList.remove(new Integer(index).intValue());
session.setAttribute("FileList", fileList);
// List<UploadFileForm> fileList = new ArrayList<UploadFileForm>();
// request.setAttribute("FileList",fileList);
return mapping.findForward("index");
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -