< html > |
< head > |
< title > |
</ title > |
</ head > |
< body > |
< form action = "upload.jsp" method = "post" enctype = "multipart/form-data" >//实现封装 |
照片名:< input type = "text" name = "name" />< br > |
上传:< input type = "file" name = "pic" />< br > |
上传:< input type = "file" name = "pic1" />< br > |
上传:< input type = "file" name = "pic2" />< br > |
上传:< input type = "file" name = "pic3" />< br > |
< input type = "submit" value = "上传" /> |
</ form > |
</ body > |
</ html > |
<%@ page contentType="html/text;charset=UTF-8"%> |
< jsp:useBean id = "smart" scope = "page" class = "org.lxh.smart.SmartUpload" />//注意应把SmartUpload.jar包放在lib下面 |
<% |
smart.initialize(pageContext);//初始化 |
smart.upload();//上传 |
%> |
<% |
try{ |
smart.save("/upload/");//保存 |
}catch(Exception e) |
{ |
e.printStackTrace(); |
} |
%> |
重命名图片方法 |
<%@ page contentType="html/text;charset=UTF-8" %> |
< jsp:useBean id = "smart" scope = "page" class = "org.lxh.smart.SmartUpload" /> |
<% |
smart.initialize(pageContext); |
smart.upload(); |
String ext=smart.getFiles().getFile(0).getFileExt(); |
String ext1=smart.getFiles().getFile(1).getFileExt(); |
String ext2=smart.getFiles().getFile(2).getFileExt(); |
String ext3=smart.getFiles().getFile(3).getFileExt(); |
%> |
<% |
String name=smart.getRequest().getParameter("name"); |
%> |
<% |
try{ |
smart.getFiles().getFile(0).saveAs("/upload/"+name+"1."+ext); |
smart.getFiles().getFile(1).saveAs("/upload/"+name+"2."+ext1); |
smart.getFiles().getFile(2).saveAs("/upload/"+name+"3."+ext2); |
smart.getFiles().getFile(3).saveAs("/upload/"+name+"4."+ext3); |
}catch(Exception e) |
{ |
e.printStackTrace(); |
} |
%> |