# Conflicts: # .idea/misc.xml # src/core/process/C_StudentUploadOpeningReport.javawmj
commit
6ed473563d
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="false" project-jdk-name="11" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="false" project-jdk-name="10" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
@ -1,19 +1,19 @@
|
|||||||
package servlet;
|
package servlet;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.MultipartConfig;
|
||||||
import javax.servlet.annotation.WebServlet;
|
import javax.servlet.annotation.WebServlet;
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@WebServlet(name = "S_StudentUploadFinishedProduct")
|
@WebServlet("/student-upload-finished-product")
|
||||||
|
@MultipartConfig
|
||||||
public class S_StudentUploadFinishedProduct extends HttpServlet {
|
public class S_StudentUploadFinishedProduct extends HttpServlet {
|
||||||
|
static String fileType = "graduation_design_finished_product";
|
||||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
String id = request.getParameter("id");
|
||||||
}
|
String fileURL = servlet.Utils.saveFile(request, fileType);
|
||||||
|
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,60 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
public interface Utils {
|
||||||
|
static Map<String,String> getVMap(String[] vName, HttpServletRequest request){
|
||||||
|
Map<String,String> vMap = new HashMap<>();
|
||||||
|
for(int i=0;i<vName.length;i++){
|
||||||
|
vMap.put(vName[i],request.getParameter(vName[i]));
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue