struts2 文件上传
来源:互联网 发布:php模板消息接口 demo 编辑:程序博客网 时间:2024/05/20 17:26
public String upload(String attachment) {
FileOutputStream fos = null;
FileInputStream fis = null;
try {
String filename = bean.getAppendix();
String attachmentFileName = filename.substring(
filename.lastIndexOf("\\"), filename.lastIndexOf("."));
String type = filename.substring(filename.lastIndexOf("."));
String realpath = ServletActionContext.getServletContext()
.getRealPath("/attachments") + attachmentFileName + type;
fos = new FileOutputStream(realpath);
fis = new FileInputStream(attachment);
byte[] buffer = new byte[1024];
int len = 0;
while ((len = fis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
return realpath;
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
close(fos, fis);
}
}
FileOutputStream fos = null;
FileInputStream fis = null;
try {
String filename = bean.getAppendix();
String attachmentFileName = filename.substring(
filename.lastIndexOf("\\"), filename.lastIndexOf("."));
String type = filename.substring(filename.lastIndexOf("."));
String realpath = ServletActionContext.getServletContext()
.getRealPath("/attachments") + attachmentFileName + type;
fos = new FileOutputStream(realpath);
fis = new FileInputStream(attachment);
byte[] buffer = new byte[1024];
int len = 0;
while ((len = fis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
return realpath;
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
close(fos, fis);
}
}
- struts2上传文件(三) struts2上传文件
- [Struts2]Struts2的文件上传
- Struts2的文件上传
- Struts2文件上传
- Struts2 上传文件实例
- struts2文件上传
- struts2文件上传
- Struts2的文件上传
- struts2-上传文件(1)
- struts2-上传文件(2)
- Struts2上传文件示例
- struts2文件上传
- Struts2实现文件上传
- struts2文件上传
- Struts2 文件上传
- ext + struts2 上传文件
- Struts2 文件上传
- Struts2的文件上传
- 一道C语言测试题
- uva oj 488
- 对类和对象的理解
- 为窗口程序添加控制台
- Android使用"中国天气网"API数据通过城市名称获取天气情况
- struts2 文件上传
- C# LDAP认证登录
- uva oj 490
- UTF-8与GB2312之间的互换
- 二叉树的非递归遍历
- 软件调试学习笔记——软中断
- 无法显示 XML 页, 无法查看使用 XSL 样式表的XML 输入。请更正错误然后单击 刷新 按钮,或稍后重试
- Android中设置文本颜色的三种方法
- Mysql时间转换(1992-02-11 10:52:12) --(1992-02-11)