I have 1 Servlet with a doPost method which will upload an image. But I need to create a Pattern object first so I can get the ID of this pattern and use this to make this the name of the image. (Not interesting for the question but now you know my motives)
This is my Servlet called CreatePatternServlet
which uses the doGet:
public void doGet(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException, java.io.IOException {
/*--------------------creating the pattern-------------------------*/
//TODO make pattern
String name = req.getParameter("name");
String scope = req.getParameter("scope");
String purpose = req.getParameter("purpose");
String problem = req.getParameter("problem");
String solution = req.getParameter("solution");
System.out.println("step 1: ["+name+","+ scope+","+purpose+","+problem+","+solution+"]");
//This method returns the id of the pattern, which will be used for the name of the image
int patternId = Controller.createPattern(name, scope, purpose, problem, solution);
/*------------------end of creating pattern-----------------------*/
And this will be the doPost in UploadImageServlet
:
doPost(HttpServletRequest req, HttpServletRespose resp) throws ServletException, IOException{
isMultipart = ServletFileUpload.isMultipartContent(req);
java.io.PrintWriter out = resp.getWriter( );
if( !isMultipart ){
return;
}
DiskFileItemFactory factory = new DiskFileItemFactory();
// maximum size that will be stored in memory
factory.setSizeThreshold(maxMemSize);
// Location to save data that is larger than maxMemSize.
factory.setRepository(new File(repository));
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
// maximum file size to be uploaded.
upload.setSizeMax( maxFileSize );
try{
// Parse the request to get file items.
List fileItems = upload.parseRequest(req);
//calling the function which loads the image in the default directory
Controller.uploadImage(fileItems, patternId);
}catch(Exception e){
System.out.println("oeps");
}
/*--------------------ending creation of image, image is created--------------------*/
}
Independently they work perfectly fine but I would like to combine them. The uploadImage can't run with a doGet so I will need some way to forward the Get request to the Post request. Is this possible? Or should I find a workaround?