struts2单文件上传案例演示(一)
来源:互联网 发布:Deepweb知乎 编辑:程序博客网 时间:2024/05/20 06:29
public class UploadAction1 extends ActionSupport implements Serializable {
private File image;//对应的就是表单中文件上传的那个输入域的名称,Struts2框架会封装成File类型的
private String imageFileName;// 上传输入域FileName 文件名
private String imageContentType;// 上传文件的MIME类型
public File getImage() {
return image;
}
public void setImage(File image) {
this.image = image;
}
public String getImageFileName() {
return imageFileName;
}
public void setImageFileName(String imageFileName) {
this.imageFileName = imageFileName;
}
public String getImageContentType() {
return imageContentType;
}
public void setImageContentType(String imageContentType) {
this.imageContentType = imageContentType;
}
public String execute(){
System.out.println(imageContentType);
try {
//处理实际的上传代码
//找到存储文件的真实路径
//System.out.println(imageFileName);
ServletContext sc = ServletActionContext.getServletContext();
String storePath = sc.getRealPath("/files");
//构建输入输出流
//OutputStream out = new FileOutputStream(storePath+"\\"+imageFileName);
//InputStream in = new FileInputStream(image);
//byte b[] = new byte[1024];
//int len = -1;
//while((len=in.read(b))!=-1){
//out.write(b, 0, len);
//}
//out.close();
//in.close();
FileUtils.copyFile(image, new File(storePath,imageFileName));
ActionContext.getContext().put("message", "上传成功!");
return SUCCESS;
} catch (Exception e) {
e.printStackTrace();
return ERROR;
}
}
}
0 0
- struts2单文件上传案例演示(一)
- struts2单文件上传案例演示(二)
- struts多文件上传案例演示(一)
- Struts2上传与下载(一)- 单文件上传
- Struts2 单文件上传
- struts2单文件上传
- struts2单文件上传
- Struts2 单文件上传
- Struts2 单文件上传
- Struts2单文件上传
- struts2单文件上传
- Struts2单文件上传
- 文件流演示案例(一)
- Struts2实现单文件上传
- Struts2之单文件上传
- struts2实现单文件上传
- struts2文件上传(单文件/多文件)
- Struts2关于文件上传的案例
- 演示 FileOutputStream案例演示
- 闪屏效果案例演示
- struts多文件上传案例演示(一)
- 标签入门(一)
- Struts2自定义类型转换器、自定义拦截器和用户输入数据的验证
- struts2单文件上传案例演示(一)
- struts2单文件上传案例演示(二)
- OC的BOOL类型
- 左手有话说(1)
- struts2防止表单重复提交
- 手把手教你开发微信公众平台2
- 史上最全Java表单验证封装类
- J2EE用监听器实现同一用户只能有一个在线
- 码农与产品经理看过来-教你用Adobe Xd轻松做原型设计^_^