List of usage examples for javax.servlet.http HttpServletRequest getServletContext
public ServletContext getServletContext();
From source file:com.test.springmvc.springmvcproject.BookDetailsController.java
@RequestMapping(value = "/{bookId}/get", method = RequestMethod.GET) public void getBook(HttpServletRequest request, HttpServletResponse response, @PathVariable Integer bookId, @ModelAttribute("bookModel") BookBean bean) { try {/* ww w.ja va 2 s. co m*/ final BookBean found = searchService.findById(bookId); final String url_totale_to_book = request.getServletContext() .getRealPath(found.getEmplacement().replaceAll(request.getContextPath(), "")); try { InputStream stream = new FileInputStream(url_totale_to_book); System.out.println(stream.toString()); response.setHeader("Content-Disposition", "attachment;filename=" + found.getNomLivre()); IOUtils.copy(stream, response.getOutputStream()); } catch (FileNotFoundException e) { } catch (IOException e) { } } catch (NoDataFoundException e) { } }
From source file:eg.agrimarket.controller.ProductController.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String productName = request.getParameter("product_Name"); List<Product> products = (List<Product>) request.getServletContext().getAttribute("products"); if (products != null) { Iterator<Product> iterator = products.iterator(); while (iterator.hasNext()) { if (iterator.next().getName().equals(productName)) { iterator.remove();/* w ww .j a va2s . co m*/ } } request.getServletContext().setAttribute("products", products); } ProductDao dao = new ProductDaoImp(); dao.removeProduct(productName); response.sendRedirect("http://" + request.getServerName() + ":" + request.getServerPort() + "/AgriMarket/admin/getProducts?#product-div"); }
From source file:CNCServicesServlet.CNCServices.java
/** * Demo Call Topup Serivce//from w ww . j a v a 2 s . c o m */ private String Topup(HttpServletRequest request) { String txtData = ""; String txtAgentCode = request.getServletContext().getInitParameter("agentCode"); String txtAgentKey = request.getServletContext().getInitParameter("agentKey"); String tranidRequest = "2016062711420056"; TopupRequest tr = new TopupRequest(txtAgentCode, "VT", tranidRequest, "0902183903", 10000, "VTT"); String trString = tr.toString(); ResponseTopup rt = new ResponseTopup(); try { txtData = Util.Encrypt(txtAgentKey, trString); Softpin soft = new Softpin(); String result = soft.getSoftpinSoap12().topup(txtAgentCode, txtData); JSONObject jsonObject = new JSONObject(result); String msg = jsonObject.isNull("msg") ? "" : jsonObject.getString("msg"); rt.setMsg(msg); String tranid = jsonObject.isNull("tranid") ? "" : jsonObject.getString("tranid"); rt.setTranid(tranid); Integer code = jsonObject.getInt("code"); rt.setCode(code); } catch (Exception e) { System.out.println("error=" + e.getMessage()); } return rt.toString(); }
From source file:CNCServicesServlet.CNCServices.java
/** * Demo Call Check Transaction Topup Service *///from w w w . j a va 2 s .co m private String CheckTranTopup(HttpServletRequest request) { String txtData = ""; String txtAgentCode = request.getServletContext().getInitParameter("agentCode"); String txtAgentKey = request.getServletContext().getInitParameter("agentKey"); String tranidRequest = "2016062711420056"; GetCardRequest gcr = new GetCardRequest(txtAgentCode, tranidRequest); String gcrString = gcr.toString(); ResponseTopup rt = new ResponseTopup(); try { txtData = Util.Encrypt(txtAgentKey, gcrString); Softpin soft = new Softpin(); String result = soft.getSoftpinSoap12().checkTranTopup(txtAgentCode, txtData); JSONObject jsonObject = new JSONObject(result); String msg = jsonObject.isNull("msg") ? "" : jsonObject.getString("msg"); rt.setMsg(msg); String tranid = jsonObject.isNull("tranid") ? "" : jsonObject.getString("tranid"); rt.setTranid(tranid); Integer code = jsonObject.getInt("code"); rt.setCode(code); } catch (Exception e) { System.out.println("error=" + e.getMessage()); } return rt.toString(); }
From source file:org.cbioportal.security.spring.PortalSavedRequestAwareAuthenticationSuccessHandler.java
private String getRelativeURI(HttpServletRequest request, String targetURI) { String relativeURI = null;/*from w w w . java 2 s . c o m*/ try { URI originalURI = new URI(targetURI); logger.debug("getRelativeURI(): request.getServletContext() = '" + request.getServletContext() + "'"); logger.debug("getRelativeURI(): testing '" + new URI(request.getContextPath()) + "'"); // URI(String scheme, String authority, String path, String query, String fragment) // use relativize so we do not include context path e.g. /cbioportal/ // use resolve to make sure we have a "/" at the front relativeURI = new URI("/") .resolve(new URI(request.getContextPath()).relativize(new URI(null, null, originalURI.getRawPath(), originalURI.getRawQuery(), originalURI.getRawFragment()))) .toString(); logger.debug("getRelativeURI(): changing '" + targetURI + "' to '" + relativeURI + "'"); } catch (URISyntaxException e) { return null; } return relativeURI; }
From source file:com.shoylpik.controller.AddProduct.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String SAVE_DIRECTORY = "shoylpik_images"; String absolutePath = request.getServletContext().getRealPath(""); String savePath = absolutePath + File.separator + SAVE_DIRECTORY; File imageSaveDirectory = new File(savePath); if (!imageSaveDirectory.exists()) { imageSaveDirectory.mkdir();//from ww w. j av a2 s .c o m } System.out.println("imageSaveDirectory.getAbsolutePath(): " + imageSaveDirectory.getAbsolutePath()); String fileName = null; //Get all the parts from request and write it to the file on server for (Part part : request.getParts()) { fileName = getFileName(part); System.out.println("fileName: " + fileName); part.write(savePath + File.separator + fileName); } try { System.out.println("savePath : " + savePath); String imageName = request.getParameter("IPimage"); System.out.println("imageName: " + imageName); Part filePart = request.getPart("IPimage"); InputStream imageInputStream = filePart.getInputStream(); Product product = new Product(); product.setProductId(Integer.parseInt(request.getParameter("IPID"))); product.setProductName(request.getParameter("IPname")); product.setProductImageName(imageName); product.setProductCategory(request.getParameter("IPcat")); product.setProductPrice(Float.parseFloat(request.getParameter("IPprice"))); product.setProductQuantity(Integer.parseInt(request.getParameter("IPQuant"))); ProductBean pBean = new ProductBean(); pBean.addProduct(product); String fullImagePath = savePath + File.separator + imageName; File file = new File(fullImagePath); System.out.println("fullImagePath : " + fullImagePath); FileOutputStream fos = new FileOutputStream(file); boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (!isMultipart) { } else { System.out.println("Inside else"); FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List items = null; try { items = upload.parseRequest(request); } catch (FileUploadException e) { } Iterator itr = items.iterator(); while (itr.hasNext()) { System.out.println("Inside while"); FileItem item = (FileItem) items.iterator(); item.write(file); } } } catch (SQLException ex) { Logger.getLogger(AddProduct.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(AddProduct.class.getName()).log(Level.SEVERE, null, ex); } response.sendRedirect("AdministrationPage.jsp"); }
From source file:CNCServicesServlet.CNCServices.java
/** * Demo Call Check Count Service/* w w w. j a v a 2 s. com*/ */ private String CheckCount(HttpServletRequest request) { String txtData = ""; String txtAgentCode = request.getServletContext().getInitParameter("agentCode"); String txtAgentKey = request.getServletContext().getInitParameter("agentKey"); CheckCountRequest ccrequest = new CheckCountRequest(txtAgentCode, "VT", 10000); String ccRequestString = ccrequest.toString(); CheckCountResponse ccResponse = new CheckCountResponse(); try { txtData = Util.Encrypt(txtAgentKey, ccRequestString); Softpin soft = new Softpin(); String result = soft.getSoftpinSoap12().checkCount(txtAgentCode, txtData); JSONObject jsonObject = new JSONObject(result); String msg = jsonObject.isNull("msg") ? "" : jsonObject.getString("msg"); ccResponse.setMsg(msg); String listprovider = jsonObject.isNull("listprovider") ? "" : jsonObject.getString("listprovider"); Integer code = jsonObject.getInt("code"); ccResponse.setCode(code); if (code == 1) { String listResult = Util.Decrypt(txtAgentKey, listprovider); ccResponse.setListprovider(listResult); System.out.println("success"); } else { ccResponse.setListprovider(""); System.out.println("Error=" + msg); } } catch (Exception e) { ccResponse.setListprovider(""); System.out.println("error=" + e.getMessage()); } return ccResponse.toString(); }
From source file:paquete.producto.Main.java
private void deleteImagen(HttpServletRequest request, String photoFileName) { String appPath = request.getServletContext().getRealPath(""); String filePath = appPath + File.separator + SAVE_DIR + File.separator + photoFileName; File photoFile = new File(filePath); photoFile.delete();/*from w ww . j a v a2s .c o m*/ }
From source file:com.liferay.portal.template.velocity.internal.VelocityManager.java
@Override public void addTaglibTheme(Map<String, Object> contextObjects, String themeName, HttpServletRequest request, HttpServletResponse response) {/* ww w .jav a 2s . co m*/ VelocityTaglib velocityTaglib = new VelocityTaglibImpl(request.getServletContext(), request, response, contextObjects); contextObjects.put(themeName, velocityTaglib); contextObjects.put("velocityTaglib_layoutIcon", _layoutIconMethod); // Legacy support contextObjects.put("theme", velocityTaglib); }
From source file:CNCServicesServlet.CNCServices.java
/** * Demo Call Get Card Service/*from w w w. jav a 2s.co m*/ */ private String GetCard(HttpServletRequest request) { String txtData = ""; String txtAgentCode = request.getServletContext().getInitParameter("agentCode"); String txtAgentKey = request.getServletContext().getInitParameter("agentKey"); String tranidRequest = "2016062711420056"; GetCardRequest gcr = new GetCardRequest(txtAgentCode, tranidRequest); String gcrString = gcr.toString(); ResponseRequest rr = new ResponseRequest(); try { txtData = Util.Encrypt(txtAgentKey, gcrString); Softpin soft = new Softpin(); String result = soft.getSoftpinSoap12().getCard(txtAgentCode, txtData); JSONObject jsonObject = new JSONObject(result); String msg = jsonObject.isNull("msg") ? "" : jsonObject.getString("msg"); rr.setMsg(msg); String tranid = jsonObject.isNull("tranid") ? "" : jsonObject.getString("tranid"); rr.setTranid(tranid); String listCards = jsonObject.isNull("listCards") ? "" : jsonObject.getString("listCards"); Integer code = jsonObject.getInt("code"); rr.setCode(code); if (code == 1) { String listResult = Util.Decrypt(txtAgentKey, listCards); rr.setListCards(listResult); System.out.println("success"); } else { rr.setListCards(""); System.out.println("Error=" + msg); } } catch (Exception e) { rr.setListCards(""); System.out.println("error=" + e.getMessage()); } return rr.toString(); }