|
|
|
@ -1,8 +1,17 @@
|
|
|
|
|
package servlet;
|
|
|
|
|
|
|
|
|
|
import gdms.Configuration;
|
|
|
|
|
import org.apache.coyote.Request;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletException;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.Part;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
@ -15,4 +24,37 @@ public interface Utils {
|
|
|
|
|
}
|
|
|
|
|
return vMap;
|
|
|
|
|
}
|
|
|
|
|
static String getFilePath(String table){
|
|
|
|
|
return Configuration.filePath+table+"/";
|
|
|
|
|
}
|
|
|
|
|
static String getFileName(String fileName){
|
|
|
|
|
SimpleDateFormat simpleDateFormat;
|
|
|
|
|
simpleDateFormat = new SimpleDateFormat("yyMMddHHmmssSSS");
|
|
|
|
|
Date date = new Date();
|
|
|
|
|
String str = simpleDateFormat.format(date);
|
|
|
|
|
str+=(int)(Math.random()*100000);
|
|
|
|
|
str+= utils.Utils.getFileType(fileName);
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
static String getFilePathName(String table, String fileName){
|
|
|
|
|
return getFilePath(table)+getFileName(fileName);
|
|
|
|
|
}
|
|
|
|
|
static String saveFile(HttpServletRequest request, String table) throws IOException, ServletException {
|
|
|
|
|
Part part = request.getPart("graduation_design");
|
|
|
|
|
String header = part.getHeader("content-disposition");
|
|
|
|
|
String path = header.substring(header.indexOf("filename=") + 10, header.length() - 1);
|
|
|
|
|
String filePathName = servlet.Utils.getFilePathName(table,path);
|
|
|
|
|
File file = new File(filePathName);
|
|
|
|
|
InputStream inputStream = part.getInputStream();
|
|
|
|
|
FileOutputStream outputStream = new FileOutputStream(file);
|
|
|
|
|
int len;
|
|
|
|
|
byte[] bytes = new byte[1024];
|
|
|
|
|
while ((len = inputStream.read(bytes)) != -1) {
|
|
|
|
|
outputStream.write(bytes, 0, len);
|
|
|
|
|
}
|
|
|
|
|
outputStream.close();
|
|
|
|
|
inputStream.close();
|
|
|
|
|
part.delete();
|
|
|
|
|
return filePathName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|