📄 webaction.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.dao.UsersDAO;
import ssh2Down.dao.Webdisk;
import ssh2Down.service.WebService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class WebAction extends ActionSupport {
private WebService webService;
private File file;
private String contentType;
private String filename;
private String downName;
private String description;
private String searchName;
private List webdisks;
private String downPath;
private String code;
private String fileName;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getDownPath() {
return downPath;
}
public void setDownPath(String downPath) {
this.downPath = downPath;
}
public List getWebdisks() {
return webdisks;
}
public void setWebdisks(List webdisks) {
this.webdisks = webdisks;
}
public String getSearchName() {
return searchName;
}
public void setSearchName(String searchName) {
this.searchName = searchName;
}
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 WebService getWebService() {
return webService;
}
public void setWebService(WebService webService) {
this.webService = webService;
}
public String upload() throws Exception {
Webdisk webdisk = new Webdisk();
webdisk.setDownName(downName);
webdisk.setFileSize((int) file.length());
webdisk.setDescription(description);
webdisk.setLoadDate(new Date());
webdisk.setSaveName(filename);
Users user = new Users();
String userName = (String) ActionContext.getContext().getSession().get(
"userService.USER_NAME");
user.setUserName(userName);
webdisk.setUsers(user);
String AbsolutePath = file.getAbsolutePath();
if (file != null) {
boolean boo = false;
boo = webService.upload(webdisk, AbsolutePath);
if (boo)
return SUCCESS;
return ERROR;
}
return ERROR;
}
public String search() throws Exception {
if (searchName == null) {
webdisks = webService.findAllFile();
} else {
webdisks = webService.findAllFileBySearchName(searchName);
}
return SUCCESS;
}
public InputStream getInputStream() throws Exception {
// 通过 ServletContext,也就是application 来读取数据
return ServletActionContext.getServletContext().getResourceAsStream(
downPath);
}
public String download() throws Exception {
Webdisk webdisk=new Webdisk();
webdisk =webService.findByCode(code) ;
String userName = webdisk.getUsers().getUserName();
fileName = webdisk.getSaveName();
downPath = "/upload2" + "/" + 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;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -