Strust2实现文件上传
来源:互联网 发布:淘宝信息发布平台 编辑:程序博客网 时间:2024/06/05 11:21
//前端页面
<form action="${pageContext.request.contextPath}/upload" enctype="multipart/form-data" method="post" > <span style="white-space:pre"> </span>上传文件:<input type="file" name="image"><br/> <span style="white-space:pre"> </span><input type="submit" value="提交"/> </form>
// strust2 配置
<action name="upload" class="com.itheima.upload.UploadFile" method="upload"> <interceptor-ref name="fileUpload"/> <interceptor-ref name="basicStack"/> <result name="success">good_result.jsp</result> </action>
//java代码
import java.io.File;import java.io.IOException;import org.apache.commons.io.FileUtils;import com.opensymphony.xwork2.ActionSupport;public class UploadFile extends ActionSupport{ private static final long serialVersionUID = 1L; private File image; //上传的文件 private String imageFileName; //文件名称 private String imageContentType; //文件类型 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 upload(){ String realpath="F:\\Leanning"; if(image != null){ File savefile = new File(new File(realpath), imageFileName); System.out.println(savefile); System.out.println(savefile.getParentFile()); savefile.getParentFile().mkdirs(); if(savefile.getParentFile().exists()){ try { FileUtils.copyFile(image, savefile); System.out.println("文件上传成功"); } catch (IOException e) { e.printStackTrace(); } } } /** * 若要存入数据库 * fileName是在entity实体类中声明存放文件名称的变量 * yu.setFileName(imageFileName) 这样将文件名称存入数据库 * 文件路径为:savefile */ return null; } }
阅读全文
1 0
- Strust2实现文件上传
- strust2文件的上传
- strust2文件上传
- strust2 文件上传
- 《Strust2》-实现照片上传
- Strust2第(十三)篇《实现文件上传和下载 》
- strust2上传文件的注意事项
- strust2文件上传大小处理问题
- strust2+extjs文件上传,提示下载
- 【问题解决】使用Strust2文件上传图片无法显示
- Strust2文件下载
- Strust2 文件下载问题
- Strust2
- strust2
- Strust2
- strust2中jquery实现ajax
- javabean实现文件上传
- jsp实现文件上传
- iphoneX布局适配及iOS 11.0系统适配
- 复合类型之引用
- sql一张表中两个字段指向同一个外键
- 实现一个函数判断year是不是闰年。
- 素数表
- Strust2实现文件上传
- golang并发ssh执行远程命令
- 创建一个数组, 实现函数init()初始化数组、 实现empty()清空数组、 实现reverse()函数完成数组元素的逆置。
- 进程间通信—共享内存、信号量
- 升级.Net Core 1.x App 及.Net Standard 1.x Library 到2.0 版
- 二维前缀和
- STM32自动完成esp8266配置
- jupyter notebook, permission denied 解决方法
- leetcode_382. Linked List Random Node ? 待解决