Advertisement
Guest User

Untitled

a guest
Feb 5th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. public void vai (HttpServletRequest request, HttpServletResponse response)
  2. Map <String,String> subFolders = new HashMap <String,String>();
  3. Map <String,String> subFoldersP = new HashMap <String,String>();
  4. Map <String,Path> subFoldersPath = new HashMap <String,Path>();
  5. String cosa = "";
  6. String nome = "";
  7. String percorso = "";
  8. int corrente,massimo = 0;
  9. int whatToShow = 0 ;
  10. Path nom = Paths.get(UPLOAD_DIRECTORY) ;
  11.  
  12. System.out.println("QueryString : " + request.getQueryString() + " ContentType : " + request.getContentType());
  13.  
  14. response.setContentType ("text/event-stream;charset=UTF-8"); //("text/html");
  15. response.setContentType("Cache-Control: no-cache");
  16. PrintWriter out = response.getWriter();
  17.  
  18. //process only if its multipart content
  19.  
  20. if(ServletFileUpload.isMultipartContent(request)){
  21. try {
  22. String Host = "third-party";
  23. String Username = "someuser";
  24. String Password = "somePWD";
  25.  
  26. String handle = "";
  27. List<FileItem> multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
  28. massimo = multiparts.size();
  29.  
  30. corrente=0;
  31. for(FileItem item : multiparts){
  32. corrente ++;
  33. whatToShow = ((corrente*100)/massimo);
  34.  
  35. if(!item.isFormField()){
  36. handle = insertIntoThirdPart(item,nom,subFolders,subFoldersP,subFoldersPath,"myDest");
  37.  
  38. } else {
  39. nome = item.getString();
  40. System.out.println("Ricevuto dal client " + nome + " e le mappe hanno dimensione " + subFolders.size() + " " + subFoldersP.size() + " " +subFoldersPath.size() );
  41. nom = Paths.get(nome);
  42. percorso = nom.toString();
  43. percorso = percorso.substring(0, (percorso.length() - nom.getFileName().toString().length()));
  44. System.out.println("Passato alla routine " + percorso);
  45. nom = Paths.get(percorso);
  46. System.out.println("come " + nom.toString());
  47. cosa = cosa + item.getString()+"<BR>";
  48. }
  49. }
  50. out.write("Files processing terminated...");
  51. out.flush();
  52. subFolders.clear();
  53. subFoldersP.clear();
  54. subFoldersPath.clear();
  55. corrente = 0;
  56.  
  57. //File uploaded successfully
  58.  
  59. } catch (Exception ex) {
  60. out.write("File Upload Failed due to " + ex); //mannaggia alla pupazza !!
  61. }
  62.  
  63. }else{
  64.  
  65. out.write("Sorry, this function in restricted for internal purposes"); // eh no ciccio !
  66. }
  67. }
  68.  
  69.  
  70.  
  71. @Override
  72. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  73. throws ServletException, IOException {
  74.  
  75. vai(request,response);
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement