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

📄 uploadfileaction.java

📁 简单的视频上传系统
💻 JAVA
字号:
package cn.com.csuinfosoft.action;

import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.upload.FormFile;

import cn.com.csuinfosoft.service.Service;
import cn.com.csuinfosoft.vo.FLVVO;
import cn.com.csuinfosoft.vo.VO;

public class UpLoadFileAction extends AbstractDispatchAction {

	private Service service = null;
	/**
	 * 文件上传
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward uploadFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		DynaActionForm uploadForm = (DynaActionForm)form;
		FLVVO flvvo = new FLVVO();
		flvvo.setFlvId(""+System.currentTimeMillis());
		flvvo.setFlvName(uploadForm.getString("flvName"));
		
		FormFile formFile = (FormFile)uploadForm.get("flvFile");
		String fileName = formFile.getFileName();
		
		logger.debug("fileName === " + fileName);
		
		String filePath = "/videoDir/"+flvvo.getFlvId()+fileName.substring(fileName.lastIndexOf("."));
		
		logger.debug("filePath === " + filePath);
		
		flvvo.setFlvPath(request.getContextPath()+filePath);
		flvvo.setFlvState(1);
		flvvo.setFlvTime(new java.sql.Timestamp(System.currentTimeMillis()));
		
		logger.info("uploadFile被执行。。。调用Service的upFileInfo方法...");
		boolean state = service.upFileInto(flvvo, this.getServlet().getServletContext().getRealPath(filePath), formFile.getFileData());
		return mapping.findForward("index");
	}

	public ActionForward showFileInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		List result = service.findByFlvInfo();
		request.setAttribute("result", result);
		return mapping.findForward("showFilePage");
	}
	
	public ActionForward testAjaxInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		List result = service.findByFlvInfo();
		JSONArray jsonArray = JSONArray.fromObject(result);
		PrintWriter pw = response.getWriter();
		pw.write(jsonArray.toString());
		pw.flush();
		pw.close();
		return null;
	}
	
	public ActionForward findFileInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		String flvId = request.getParameter("flvId");
		VO vo = service.loadByFlvInfo(flvId);
		request.setAttribute("flvVO", vo);
		return mapping.findForward("loadFilePage");
	}

	public void setService(Service service) {
		this.service = service;
	}
}

⌨️ 快捷键说明

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