struts2上传多文件(b)
来源:互联网 发布:凸优化 公开课 编辑:程序博客网 时间:2024/06/05 09:47
UploadUtil.java<br>-------------------
/**
* 上传文件,名称以日期命名
*
* @author Administrator
*/
public
class
UploadUtil {
/**
* 上传文件
*
* @param src
* 源文件
* @param dst
* 目标文件
* @param BUFFER_SIZE
* 缓冲大小
*/
public
static
void
copy(File src, File dst,
final
int
BUFFER_SIZE) {
try
{
InputStream in =
null
;
OutputStream out =
null
;
try
{
in =
new
BufferedInputStream(
new
FileInputStream(src));
dst = rename(dst);
out =
new
BufferedOutputStream(
new
FileOutputStream(dst));
int
word =
0
;
while
((word = in.read()) != -
1
) {
out.write(word);
}
}
finally
{
if
(
null
!= in) {
in.close();
}
if
(
null
!= out) {
out.close();
}
}
}
catch
(Exception e) {
e.printStackTrace();
}
}
/**
* 得到扩展名
* @param fileName
* @return
*/
public
static
String getExt(String fileName) {
int
pos = fileName.lastIndexOf(
"."
);
return
fileName.substring(pos);
}
/**
* 更改上传文件名
* @param file 文件对象
* @return 更名后的文件对象
*/
public
static
File rename(File file) {
String fileName =
""
;
// 文件名
String extName =
""
;
// 文件扩展名
Calendar cal = Calendar.getInstance();
SimpleDateFormat formatter =
new
SimpleDateFormat(
"yyyyMMddHHmmss"
);
fileName = formatter.format(cal.getTime()) + (
int
) (Math.random() *
10
);
extName = getExt(file.getName());
String newName = fileName +
"."
+ extName;
file =
new
File(file.getParent(), newName);
return
file;
}
}
upload.jsp
<html>
<body>
<s:form method=
"post"
action=
"jupload"
enctype =
"multipart/form-data"
>
上传图片:<s:file name =
"upload"
theme=
"simple"
/>
<br/>
上传附件:<s:file name =
"upload"
theme=
"simple"
/>
<br/>
<s:submit theme=
"simple"
value=
"提交"
/>
</s:form>
</body>
</html>
struts.xml
<!-- 上传文件 cyjch -->
<action name=
"jupload"
method=
"add"
class
=
"upAction"
>
<result name=
"upload"
>upload.jsp</result>
</action>
0 0
- struts2上传多文件(b)
- Struts2多文件上传
- struts2多文件上传
- struts2多文件上传
- struts2 多文件上传
- struts2多文件上传
- struts2多文件上传
- struts2多文件上传
- struts2多文件上传
- Struts2多文件上传
- Struts2多文件上传
- Struts2 多文件上传
- struts2多文件上传
- struts2 多文件上传
- Struts2多文件上传
- struts2多文件上传
- struts2 多文件上传
- struts2多文件上传
- redis 常见指令操作
- JAVA加减日期
- Java基础-Java中的Calendar和Date类
- struts2上传多文件
- 对VC初学者的益言
- struts2上传多文件(b)
- 【转载】FckEditor 2.6.3 for Java 2.4 配置
- 【转载】ckeditor 中去掉\'浏览服务器\'按钮
- 判断字符串中包含某个字符串
- 【转载】FCKeditor 2.6.3 与FCKeditor.java 2.4在JSP中配置
- 【转载】Myeclipse10 安装Aptana插件
- iOS适配HTTPS、开启ATS让你的域名更安全
- 【转载】servlet 上传文件
- 【转载】apache-tomcat-7.0.40加大内存配置
原创粉丝点击
热门IT博客
热门问题
老师的惩罚
人脸识别
我在镇武司摸鱼那些年
重生之率土为王
我在大康的咸鱼生活
盘龙之生命进化
天生仙种
凡人之先天五行
春回大明朝
姑娘不必设防,我是瞎子
采蝶轩的小蛋糕
小蛋糕英文
烤小蛋糕机器
小西点蛋糕图片
夹心小蛋糕
小面包蛋糕
可爱的蛋糕
嘟嘟蛋糕
趣味蛋糕
无糖蛋糕店
小跳蛙歌词完整的
小跳蛙铃声下载
我是一只小跳蛙
小跳蛙幼儿舞蹈
儿童歌曲小跳蛙
小跳蛙童声是谁
小跳蛙教案
小蛙跳
小蛮幺减肥有激素吗
小蛮妻
绝世倾城将军狂宠小蛮妻
小蛮腰全文阅读
古典小蛮腰
小蛮腰mp3在线试听
小蛮腰广州
小蛮腰全文免费阅读
亚洲小蛮腰
小蛮腰多高
小蛮腰减肥效果
小蛮腰网站y
小蛮腰 伦桑
小蛮腰歌曲苏三
小蛮腰伦桑在线收听
小蛮腰萧忆情
小蛮腰伦桑mp3
小蛮腰下载
小蛮腰是什么意思
广州小蛮腰在哪
小蛮腰 歌曲
小蛮腰多少层
小蛮腰在线听