List of usage examples for javax.servlet ServletContext getRealPath
public String getRealPath(String path);
From source file:productsave.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); try {/* w ww. j a v a 2s.c o m*/ ServletContext x = this.getServletContext(); String path = x.getRealPath("/images"); System.out.println(path + " path"); DiskFileUpload p = new DiskFileUpload(); List q = p.parseRequest(request); Iterator z = q.iterator(); while (z.hasNext()) { FileItem f = (FileItem) z.next(); if (f.isFormField() == true) { //non-file data System.out.println("executed"); String h = f.getFieldName(); String data = f.getString(); if (h.equalsIgnoreCase("productname")) { productname = data; } else if (h.equalsIgnoreCase("category")) { categoryid = data; System.out.println(categoryid + " cccc"); } else if (h.equalsIgnoreCase("price")) { price = data; } else if (h.equalsIgnoreCase("description")) { description = data; } } else { //file data String filename = f.getName(); if (filename != null && filename.length() > 0) { File g = new File(filename); filename = g.getName(); //creating unique file name long w = System.currentTimeMillis(); filename = w + filename; System.out.println("path " + path + " file " + filename); //upload file File t = new File(path, filename); f.write(t); if (f.getFieldName().equals("image")) { image = filename; } } } } } catch (Exception e) { e.printStackTrace(); } productbean product = new productbean(); product.setProductname(productname); product.setCategoryid(categoryid); product.setDescription(description); product.setImage(image); product.setPrice(price); int count = product.save(); if (count != 0) { out.println("1"); } else { out.println("0"); } }
From source file:dto.Image.java
public String execute() { try {//from w w w . j a va 2 s . co m HttpSession srvltSession = this.servletRequest.getSession(); ServletContext srvlContxt = srvltSession.getServletContext();// .getServletContext() String filePath = srvlContxt.getRealPath("/").concat("userimages"); System.out.println("Image Location:" + filePath); File destFile = new File(filePath, this.imageUploadFileName); FileUtils.copyFile(this.imageUpload, destFile); } catch (Exception e) { System.err.println(e); return ERROR; } return SUCCESS; }
From source file:edu.cornell.mannlib.vitro.webapp.controller.freemarker.SmokeTestController.java
private void readSmokeTestClassesFromFile(String p, ServletContext context) { //check that this is a file and not a directory. File f = new File(context.getRealPath(p)); if (f.exists() && f.isFile()) { InputStream fileStream = context.getResourceAsStream(p); listOfSmokeTestClasses.addAll(getContentsFromFileStream(fileStream)); } else {/* ww w. j a v a2 s.c om*/ if (!f.exists()) { log.debug("File for path " + p + " does not exist"); } else if (f.isDirectory()) { log.debug("Path " + p + " corresponds to a directory and not file. File was not read."); } } }
From source file:productupdate.java
void getformdata() { try {//w w w . j a v a2 s . com ServletContext x = this.getServletContext(); String path = x.getRealPath("/images"); System.out.println(path + " path"); DiskFileUpload p = new DiskFileUpload(); List q = p.parseRequest(request); Iterator z = q.iterator(); while (z.hasNext()) { FileItem f = (FileItem) z.next(); if (f.isFormField() == true) { //non-file data String h = f.getFieldName(); String data = f.getString(); if (h.equalsIgnoreCase("productid")) { productid = data; } else if (h.equalsIgnoreCase("productname")) { productname = data; } else if (h.equalsIgnoreCase("category")) { categoryid = data; } else if (h.equalsIgnoreCase("price")) { price = data; } else if (h.equalsIgnoreCase("description")) { description = data; } else if (h.equalsIgnoreCase("status")) { System.out.println("status " + status); status = data; } } else { //file data String filename = f.getName(); if (filename != null && filename.length() > 0) { File g = new File(filename); filename = g.getName(); //creating unique file name long w = System.currentTimeMillis(); filename = w + filename; System.out.println("path " + path + " file " + filename); //upload file File t = new File(path, filename); f.write(t); if (f.getFieldName().equals("image")) { System.out.println("images " + image); image = filename; } } } } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.siphon.d2js.jshttp.ServerUnitManager.java
public ServerUnitManager(ServletContext servletContext) { this.servletContext = servletContext; this.srcFolder = servletContext.getRealPath(""); }
From source file:org.fosstrak.ale.server.persistence.impl.PersistenceInitImpl.java
@Override public void init(ServletContext servletContext) throws ServletException { try {//from www . j a v a 2 s .co m LOG.info("ALE Persistence => start"); String path = servletContext.getRealPath("/"); LOG.debug("ALE Persistence real path of the webapp: " + path); persistenceConfig.setRealPathWebapp(path); LOG.info("ALE Persistence initialize configuration"); persistenceReadConfig.init(); LOG.info("ALE Persistence => end"); } catch (Exception ex) { LOG.error("could not initialize the persistence API.", ex); throw new ServletException(ex); } }
From source file:com.rhythm.louie.info.DownloadServlet.java
private String findPythonFile() { ServletContext context = getServletConfig().getServletContext(); String rp = context.getRealPath("."); File dir = new File(rp); FileFilter fileFilter = new WildcardFileFilter("*-python.zip"); File[] files = dir.listFiles(fileFilter); if (files.length == 1) { return files[0].getAbsolutePath(); //if there are multiple things that match that pattern, we have bigger issues } else if (files.length > 1) { LoggerFactory.getLogger(DownloadServlet.class) .error("Multiple files matching *-python.zip were located. Cannot resolve."); }// w ww .ja v a 2 s. co m return ""; }
From source file:mayo.edu.server.JsonServiceImpl.java
public String getBasePath() { String dataPath;//from w w w . j ava 2s. c om HttpSession httpSession = getThreadLocalRequest().getSession(true); ServletContext context = httpSession.getServletContext(); String realContextPath = context.getRealPath(getThreadLocalRequest().getContextPath()); if (isDevelopmentMode()) { dataPath = realContextPath; } else { dataPath = realContextPath + "/../"; } return dataPath; }
From source file:org.cipango.sipatra.DefaultContextLoader.java
public void contextInitialized(ServletContextEvent sce) { ServletContext servletContext = sce.getServletContext(); String appPath = servletContext.getRealPath("/WEB-INF/sipatra"); String scriptPath = PropertyUtils.getStringProperty(Properties.SIPATRA_PATH_PROPERTY, null, servletContext); if (scriptPath == null) { scriptPath = appPath + "/application.rb"; } else {//from ww w . j a v a2 s .c o m File file = new File(scriptPath); if (!file.exists()) { _log.error(file.getAbsolutePath() + " does not exist!"); scriptPath = null; } if (file.isFile()) { if (!file.getName().endsWith(".rb")) _log.warn(file.getAbsolutePath() + " is not a ruby file!"); if (file.getParentFile() != null) appPath = file.getParentFile().getAbsolutePath(); else _log.error(file.getAbsolutePath() + " got no parent directory!"); } else if (file.isDirectory()) { appPath = new File(scriptPath).getAbsolutePath(); } } Config conf = new Config(); conf.maxActive = PropertyUtils.getIntegerProperty(Properties.SIPATRA_POOL_MAX_ACTIVE_PROPERTY, -1, servletContext); conf.maxIdle = PropertyUtils.getIntegerProperty(Properties.SIPATRA_POOL_MAX_IDLE_PROPERTY, -1, servletContext); conf.maxWait = PropertyUtils.getIntegerProperty(Properties.SIPATRA_POOL_MAX_WAIT_PROPERTY, -1, servletContext); conf.minIdle = PropertyUtils.getIntegerProperty(Properties.SIPATRA_POOL_MIN_IDLE_PROPERTY, -1, servletContext); conf.minEvictableIdleTimeMillis = PropertyUtils .getLongProperty(Properties.SIPATRA_POOL_MIN_EVICTABLE_PROPERTY, 1000L * 60L * 30L, servletContext); conf.lifo = PropertyUtils.getBooleanProperty(Properties.SIPATRA_POOL_LIFO, false, servletContext); conf.numTestsPerEvictionRun = PropertyUtils.getIntegerProperty(Properties.SIPATRA_POOL_TEST_EVICTION_RUN, 3, servletContext); conf.softMinEvictableIdleTimeMillis = PropertyUtils .getLongProperty(Properties.SIPATRA_POOL_SOFT_MIN_EVICTABLE, -1L, servletContext); conf.testOnBorrow = PropertyUtils.getBooleanProperty(Properties.SIPATRA_POOL_TEST_BORROW, false, servletContext); conf.testOnReturn = PropertyUtils.getBooleanProperty(Properties.SIPATRA_POOL_TEST_RETURN, false, servletContext); conf.testWhileIdle = PropertyUtils.getBooleanProperty(Properties.SIPATRA_POOL_TEST_IDLE, false, servletContext); conf.timeBetweenEvictionRunsMillis = PropertyUtils.getLongProperty(Properties.SIPATRA_POOL_TIME_EVICTION, -1L, servletContext); GenericObjectPool pool = new GenericObjectPool(new JRubyRuntimeFactory(appPath, scriptPath), conf); startPool(pool, PropertyUtils.getIntegerProperty(Properties.SIPATRA_POOL_INIT_POOL_SIZE, 1, servletContext)); servletContext.setAttribute(Attributes.POOL, pool); }
From source file:org.glimpse.server.GlimpseManager.java
public void setServletContext(ServletContext servletContext) { String confDirPath = System.getProperty("org.glimpse.conf.dir"); if (StringUtils.isEmpty(confDirPath)) { confDirPath = servletContext.getRealPath("/WEB-INF/conf"); }/*ww w. j av a2 s .c om*/ configurationDirectory = new File(confDirPath); try { configuration = new PropertiesConfiguration(new File(configurationDirectory, "glimpse.properties")); } catch (ConfigurationException e) { logger.fatal("Unable to Load configuration", e); throw new RuntimeException(e); } }