uploadaction.java

来自「关于Struts2的一些编程例子集合!希望对学习Struts2的朋友有帮助!」· Java 代码 · 共 40 行

JAVA
40
字号
package com.briup;import java.io.*;import org.apache.struts2.ServletActionContext;public class UploadAction {	private File icon;	private String iconFileName;	//路径 /upload(“/”表示web应用下) ->/opt/tomcat/webapps/struts_jd0808a/upload	private String savePath;	public File getIcon() {		return icon;	}	public void setIcon(File icon) {		this.icon = icon;	}	public String getIconFileName() {		return iconFileName;	}	public void setIconFileName(String iconFileName) {		this.iconFileName = iconFileName;	}	public String getSavePath() {		return ServletActionContext.getRequest().getSession().getServletContext().getRealPath(savePath);	}	public void setSavePath(String savePath) {		this.savePath = savePath;	}	public String execute() throws Exception{		BufferedInputStream in=new BufferedInputStream(new FileInputStream(icon));		BufferedOutputStream out=new BufferedOutputStream(new FileOutputStream(getSavePath()+"/"+iconFileName));		byte[] buffer=new byte[1024];		int i=-1;		while((i=in.read(buffer))!=-1){			out.write(buffer, 0, i);		}		out.close();		in.close();		return "success";	}}

⌨️ 快捷键说明

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