|
|
@@ -153,63 +153,68 @@ public class ActivityServlet extends HttpServlet {
|
|
|
String desc = CommentUtils.myToString(request.getParameter("desc"));
|
|
|
String pic = null, video = null;
|
|
|
|
|
|
- DiskFileItemFactory factory = new DiskFileItemFactory();
|
|
|
- ServletFileUpload sfu = new ServletFileUpload(factory);
|
|
|
- List items = sfu.parseRequest(request);// 从request得到所有上传域的列表
|
|
|
- for (Iterator iter = items.iterator(); iter.hasNext(); ) {
|
|
|
- FileItem fileitem = (FileItem) iter.next();
|
|
|
- if (!fileitem.isFormField()) {
|
|
|
- String rootPath = request.getRealPath("/");
|
|
|
- String relativePath;
|
|
|
- String fileName;
|
|
|
- if (fileitem.getContentType().contains("video")) {
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
- relativePath = "upload/video/" + sdf.format(new Date()) + "/";
|
|
|
- File file = new File(rootPath + relativePath);
|
|
|
- if (!file.exists()) {
|
|
|
- file.mkdirs();
|
|
|
- }
|
|
|
- String uuid = MD5Util.MD5(UUID.randomUUID().toString() + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()).toString());
|
|
|
- fileName = uuid + ".mov";
|
|
|
-
|
|
|
- InputStream fin = fileitem.getInputStream();
|
|
|
- FileOutputStream fout = new FileOutputStream(rootPath + relativePath + fileName);
|
|
|
- byte[] b = new byte[1024];
|
|
|
- int length = 0;
|
|
|
- while ((length = fin.read(b)) > 0) {
|
|
|
- fout.write(b, 0, length);
|
|
|
- }
|
|
|
- fin.close();
|
|
|
- fout.close();
|
|
|
- video = relativePath + fileName;
|
|
|
- System.out.println("file:" + relativePath + fileName);
|
|
|
- } else if (fileitem.getContentType().contains("image")) {
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
- relativePath = "upload/photo/" + sdf.format(new Date()) + "/";
|
|
|
- File file = new File(rootPath + relativePath);
|
|
|
- if (!file.exists()) {
|
|
|
- file.mkdirs();
|
|
|
- }
|
|
|
- String uuid = MD5Util.MD5(UUID.randomUUID().toString() + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()).toString());
|
|
|
- fileName = uuid + ".jpg";
|
|
|
-
|
|
|
- InputStream fin = fileitem.getInputStream();
|
|
|
- FileOutputStream fout = new FileOutputStream(rootPath + relativePath + fileName);
|
|
|
- byte[] b = new byte[1024];
|
|
|
- int length = 0;
|
|
|
- while ((length = fin.read(b)) > 0) {
|
|
|
- fout.write(b, 0, length);
|
|
|
+ try {
|
|
|
+ DiskFileItemFactory factory = new DiskFileItemFactory();
|
|
|
+ ServletFileUpload sfu = new ServletFileUpload(factory);
|
|
|
+ List items = sfu.parseRequest(request);// 从request得到所有上传域的列表
|
|
|
+ for (Iterator iter = items.iterator(); iter.hasNext(); ) {
|
|
|
+ FileItem fileitem = (FileItem) iter.next();
|
|
|
+ if (!fileitem.isFormField()) {
|
|
|
+ String rootPath = request.getRealPath("/");
|
|
|
+ String relativePath;
|
|
|
+ String fileName;
|
|
|
+ if (fileitem.getContentType().contains("video")) {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
+ relativePath = "upload/video/" + sdf.format(new Date()) + "/";
|
|
|
+ File file = new File(rootPath + relativePath);
|
|
|
+ if (!file.exists()) {
|
|
|
+ file.mkdirs();
|
|
|
+ }
|
|
|
+ String uuid = MD5Util.MD5(UUID.randomUUID().toString() + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()).toString());
|
|
|
+ fileName = uuid + ".mov";
|
|
|
+
|
|
|
+ InputStream fin = fileitem.getInputStream();
|
|
|
+ FileOutputStream fout = new FileOutputStream(rootPath + relativePath + fileName);
|
|
|
+ byte[] b = new byte[1024];
|
|
|
+ int length = 0;
|
|
|
+ while ((length = fin.read(b)) > 0) {
|
|
|
+ fout.write(b, 0, length);
|
|
|
+ }
|
|
|
+ fin.close();
|
|
|
+ fout.close();
|
|
|
+ video = relativePath + fileName;
|
|
|
+ System.out.println("file:" + relativePath + fileName);
|
|
|
+ } else if (fileitem.getContentType().contains("image")) {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
+ relativePath = "upload/photo/" + sdf.format(new Date()) + "/";
|
|
|
+ File file = new File(rootPath + relativePath);
|
|
|
+ if (!file.exists()) {
|
|
|
+ file.mkdirs();
|
|
|
+ }
|
|
|
+ String uuid = MD5Util.MD5(UUID.randomUUID().toString() + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()).toString());
|
|
|
+ fileName = uuid + ".jpg";
|
|
|
+
|
|
|
+ InputStream fin = fileitem.getInputStream();
|
|
|
+ FileOutputStream fout = new FileOutputStream(rootPath + relativePath + fileName);
|
|
|
+ byte[] b = new byte[1024];
|
|
|
+ int length = 0;
|
|
|
+ while ((length = fin.read(b)) > 0) {
|
|
|
+ fout.write(b, 0, length);
|
|
|
+ }
|
|
|
+ fin.close();
|
|
|
+ fout.close();
|
|
|
+ pic = relativePath + fileName;
|
|
|
+ System.out.println("file:" + relativePath + fileName);
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
}
|
|
|
- fin.close();
|
|
|
- fout.close();
|
|
|
- pic = relativePath + fileName;
|
|
|
- System.out.println("file:" + relativePath + fileName);
|
|
|
- } else {
|
|
|
- break;
|
|
|
}
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
Map<String, Object> map = activityService.enroll(pk, parttyPk, people, tel, pCount, fee, pic, video, desc);
|
|
|
int code = (int) map.get("result");
|
|
|
|