package cn.File.Action;
import java.io.FileOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;
import org.apache.struts.util.MessageResources;
import cn.File.Form.FileForm;
import cn.File.Model.FileModel;
public class FileAction extends Action {
public ActionForward execute(ActionMapping arg0, ActionForm arg1,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
FileForm form = (FileForm) arg1;
FormFile path = form.getPath();
String name = path.getFileName();// 只可以上传RAR的文件
String ext = name.substring(name.lastIndexOf(".") + 1);
byte b[] = path.getFileData();
ActionForward f = null;
if (ext.equals("rar") && b.length < 10 * 1024 * 1024)// 限制上传文件的大小
{
String filePath = this.servlet.getServletContext().getRealPath(
"File").replaceAll("\\\\", "/")
+ "/" + path.getFileName();
FileOutputStream fo = new FileOutputStream(filePath);
fo.write(b, 0, b.length);
fo.close();
FileModel model = new FileModel();
model.savefile("/File/" + path.getFileName(), form.getFilename());
request.setAttribute("file", "上传成功!");// 上传成功返回的成功信息
f = new ActionForward("/File.jsp");
form.setFilename("");// 页面返回的时候文本框里没有上次写入的值
} else {
MessageResources r = this.getResources(request);// 获取资源文件里的错误信息,返回给asp页面
String er = r.getMessage(request.getLocale(),
"UserBlog.aspfileerror");
request.setAttribute("asperror", er);
f = new ActionForward("/File.jsp");
}
return f;
}
}
Struts上传文件
需积分: 0 103 浏览量
2008-10-10
09:53:35
上传
评论
收藏 1.43MB RAR 举报
叼奶嘴的超人
- 粉丝: 62
- 资源: 57
最新资源
- 基于paddle搭建神经网络实现水果识别分类python源码+数据集(高分项目).zip
- 三菱plc编程口通信学习笔记.doc
- 与HIS接口解决方案...doc
- 专利技术交底书-案例模板-软件类-样板示例.doc
- C# 超简单的人脸识别库 .zip
- 实现人脸识别资源代码.zip
- 东北大学-微机原理实验报告及答案-8255并行接口.doc
- 实现人脸检测,人脸识别,人脸标记68个坐标点 人脸对齐 人脸特征测试等 同时可以自行训练人脸识别库.zip
- 基于中科视拓 seetaface6基础源码和JNI源码编译而来的项目.zip
- Python基于opencv人脸识别的考勤系统源码+代码说明(毕业设计).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0