Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package controllers; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.multipart.MultipartFile; /** * * @author bezdatiuzer */ @Controller @RequestMapping("/Constructor") public class ConstructorController { @RequestMapping("/show") public String show(HttpServletRequest request, Map<String, Object> model) { List<File> telems = new ArrayList(); HashMap<Integer, String> elemMap = new HashMap(); String sid = request.getSession().getId(); String path = "/usr/local/tomcat/tomcat/webapps/ROOT/public/constructor/" + sid + "/"; int i = 0; File f = new File(path + i); if (f.exists()) { elemMap.put(i, "/public/constructor/" + sid + "/" + i); model.put("telems", elemMap); } /*while(f.exists()){ f = new File(path+(i)); elemMap.put(i,path+(i++)); //telems.add(f); }*/ model.put("telems", elemMap); return "/../construct"; } //@ResponseBody @RequestMapping("/uploadTemplateElement") public String uploadTemplateElement(HttpServletRequest request, Map<String, Object> model, @RequestParam(value = "templateElem", required = false) MultipartFile templateElem) throws IOException { String sid = request.getSession().getId(); String path = "/usr/local/tomcat/tomcat/webapps/ROOT/public/constructor/" + sid + "/"; int i = 0; File file = new File(path); if (!file.exists()) { file.mkdirs(); } while (file.exists()) { file = new File(path + (i++)); } templateElem.transferTo(file); //return "redirect:/Constructor/show"; return "redirect:/Constructor/show"; } }