博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
struts2 中的文件上传
阅读量:4222 次
发布时间:2019-05-26

本文共 1593 字,大约阅读时间需要 5 分钟。

struts.xml
/uploadFiles
/JSP/success.jsp
action
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionSupport; public class UploadAction extends ActionSupport {
private static final long serialVersionUID = 1L; private String title; private File upload; private String uploadContentType; private String uploadFileName; private String savePath; public String getTitle() {
return title; } public void setTitle(String title) {
this.title = title; } public File getUpload() {
return upload; } public void setUpload(File upload) {
this.upload = upload; } public String getUploadContentType() {
return uploadContentType; } public void setUploadContentType(String uploadContentType) {
this.uploadContentType = uploadContentType; } public String getUploadFileName() {
return uploadFileName; } public void setUploadFileName(String uploadFileName) {
this.uploadFileName = uploadFileName; } public String getSavePath() {
return ServletActionContext.getServletContext().getRealPath("/WEB-INF/" + savePath); } public void setSavePath(String savePath) {
this.savePath = savePath; } public String execute() throws Exception {
FileOutputStream fos = new FileOutputStream(getSavePath() + "\\" + getUploadFileName()); FileInputStream fis = new FileInputStream(getUpload()); byte[] buffer = new byte[1024]; int len = 0; while((len = fis.read(buffer)) > 0) {
fos.write(buffer, 0, len); } fos.close(); return SUCCESS; } }

转载地址:http://wkgmi.baihongyu.com/

你可能感兴趣的文章
函数入栈出栈以及栈帧
查看>>
从RTTI谈C++的向下转型
查看>>
面试心得(BAT)
查看>>
Windows Server 2012 Web方式修改域用户密码-通过Remote Desktop Web实现
查看>>
华为USG5300 采用IKE安全策略方式建立IPSec隧道
查看>>
Centos7 nginx访问日志文件割接
查看>>
我是一条内存!
查看>>
OIM API Usage
查看>>
OIM实现OIM用户修改、OIM用户Disable流程审批
查看>>
UEFI与MBR区别
查看>>
Ubuntu每次开机后提示:检测到系统程序出现问题的解决方法
查看>>
CC2640 看门狗配置
查看>>
linnux外网不通,提示Destination Host Unreachable解决
查看>>
为strawberry perl安装PadWalker
查看>>
Notepad++的字体设置加Consolas和微软雅黑混合字体
查看>>
gdb 调试常用命令
查看>>
POJ 3125 (Queue)
查看>>
trees in a row
查看>>
在VirtualBox中安装Ubuntu
查看>>
ubuntu mount cifs
查看>>