⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uploadfileaction.java

📁 在j2ee开发时
💻 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");
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -