发布网友
共1个回答
热心网友
String time = new SimpleDateFormat("yyyyMMddHHmmss")
.format(Calendar.getInstance().getTime());// 得到系统时间
// 上传技术
SmartUpload up = new SmartUpload();
// 进行初始化
up.initialize(this.getServletConfig(), request, response);
// 开始上传
try {
up.upload("utf-8");//设置编码方式。
int id = Integer.parseInt(up.getRequest().getParameter("id"));// 商品编号
SmartFiles sf = up.getFiles();// 得到上传的所有图片
SmartFile file = sf.getFile(0);// 根据索引得到上传图片 多个图片可以用循环:
String type = file.getFileExt();// 得到图片后缀名
String folder = "tp/";// 指定文件夹
String path = folder + time + "." + type;// 路径
System.out.println(path + "路径");
file.saveAs(request.getRealPath("/") + path);// 保存图片
} catch (Exception e) {
e.printStackTrace();
}
//你搞个邮箱我把SmartUploadjar包 发给你吧。 //设置from提交
/*<form action="SellerServet" method="post"
enctype="multipart/form-data">*/ // 加上 enctype="multipart/form-data