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

📄 fileaction.java

📁 在myMyEclipse坏境下
💻 JAVA
字号:
package ssh2Down.action;

import java.io.File;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import ssh2Down.dao.Downfile;
import ssh2Down.dao.Users;
import ssh2Down.service.FileService;
import ssh2Down.service.UserService;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class FileAction extends ActionSupport {
	private FileService fileService;
	private UserService userService;
	private File file;
	private String contentType;
	private String filename;
	private String downName;
	private String description;
	private String fileName;
	private List downfiles;
	private String downPath;// 指定要被下载的文件路径
	private String code;
	private String searchName;
	private List downRecordList;

	

	public List getDownRecordList() {
		return downRecordList;
	}

	public void setDownRecordList(List downRecordList) {
		this.downRecordList = downRecordList;
	}

	public String getSearchName() {
		return searchName;
	}

	public void setSearchName(String searchName) {
		this.searchName = searchName;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getDownPath() {
		return downPath;
	}

	public void setDownPath(String downPath) {
		this.downPath = downPath;
	}

	public List getDownfiles() {
		return downfiles;
	}

	public void setDownfiles(List downfiles) {
		this.downfiles = downfiles;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public FileService getFileService() {
		return fileService;
	}

	public void setFileService(FileService fileService) {
		this.fileService = fileService;
	}

	public File getFile1() {
		return file;
	}

	public void setFile1(File file) {
		this.file = file;
	}

	public String getFile1ContentType() {
		return contentType;
	}

	public void setFile1ContentType(String contentType) {
		this.contentType = contentType;
	}

	public String getFile1FileName() {
		return filename;
	}

	public void setFile1FileName(String filename) {
		this.filename = filename;
	}

	public String getDownName() {
		return downName;
	}

	public void setDownName(String downName) {
		this.downName = downName;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public String upload() throws Exception {
		Downfile downfile = new Downfile();
		downfile.setDownName(downName);
		downfile.setFileSize((int) file.length());
		downfile.setDescription(description);
		downfile.setLoadDate(new Date());
		downfile.setSaveName(filename);
		Users user = new Users();
		String userName = (String) ActionContext.getContext().getSession().get(
				"userService.USER_NAME");

		user.setUserName(userName);
		downfile.setUsers(user);
		String AbsolutePath = file.getAbsolutePath();
		if (file != null) {
			boolean boo = false;
			boo = fileService.upload(downfile, AbsolutePath);
			if (boo)
				return SUCCESS;
			return ERROR;
		}
		return ERROR;
	}

	public String search() throws Exception {
		if (searchName == null) {
			downfiles = fileService.findAllFile();
		} else {
			downfiles = fileService.findAllFileByFileName(searchName);
		}
		return SUCCESS;
	}

	public InputStream getInputStream() throws Exception {
		// 通过 ServletContext,也就是application 来读取数据
		return ServletActionContext.getServletContext().getResourceAsStream(
				downPath);
	}

	

	public String download() throws Exception {
		Downfile downfile = new Downfile();
		downfile = fileService.findByCode(code);
		String userName = downfile.getUsers().getUserName();
		fileService.addRecord(code, userName);
		fileName = downfile.getSaveName();
		downPath = "/upload1" + "/" + userName + "/" + code + "/" + fileName;
		getInputStream();
		getDownloadFileName();
		return SUCCESS;
	}

	/** 提供转换编码后的供下载用的文件名 */
	public String getDownloadFileName() {
		String downFileName = fileName;
		try {
			downFileName = new String(downFileName.getBytes(), "ISO8859-1");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return downFileName;
	}

	public String downRecord() throws Exception {
		String userName=(String) ActionContext.getContext().getSession().get("userService.USER_NAME");
		downRecordList=fileService.recordByUser(userName);
		return SUCCESS;
	}

	public String llel() throws Exception {
		return SUCCESS;
	}

	public String lwll() throws Exception {
		return SUCCESS;
	}

	public String llesl() throws Exception {
		return SUCCESS;
	}

}

⌨️ 快捷键说明

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