List of usage examples for javax.servlet.http HttpServletRequest getRequestDispatcher
public RequestDispatcher getRequestDispatcher(String path);
From source file:controller.editGames.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { boolean isMultiPart = ServletFileUpload.isMultipartContent(request); if (isMultiPart) { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List items = upload.parseRequest(request); Iterator<FileItem> iter = items.iterator(); while (iter.hasNext()) { FileItem fileItem = iter.next(); if (fileItem.isFormField()) { processFormField(fileItem); } else { flItem = fileItem;/*from w w w. jav a 2 s . c om*/ } } } Check b = new Check(); b.setMinCpu(MinCpu); b.setMinCpuLvl(MinCpuLvl); b.setMinGpu(MinGpu); b.setMinGpuLvl(MinGpuLvl); b.setMinRam(MinRam); b.setCode(Code); b.setRecCpuLvl(RecCpuLvl); b.setRecCpu(RecCpu); b.setRecGpu(RecGpu); b.setRecGpuLvl(RecGpuLvl); b.setRecRam(RecRam); int i = b.editGame(); if (i > 0) { RequestDispatcher rd = request.getRequestDispatcher("viewGames.jsp"); request.setAttribute("return", "Edit Item is Successful."); rd.forward(request, response); } else { RequestDispatcher rd = request.getRequestDispatcher("editGames.jsp"); request.setAttribute("return", "Edit Item is Failed."); rd.forward(request, response); } } catch (Exception e) { System.out.println(e); } }
From source file:com.edgenius.wiki.webapp.servlet.InstallServlet.java
/** * @param request//from w w w . j a va 2 s. c o m * @param response * @throws IOException * @throws ServletException */ private void createLicense(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String type = request.getParameter("licenseType"); if (!"free".equals(type)) { String license = StringUtils.trimToEmpty(request.getParameter("license")); if (license != "") { //validate license if (LicenseManager.verfiyLicense(license, 0) != 0) { request.setAttribute("message", "Invalid license, please verify your input."); //echo back message request.setAttribute("license", license); request.getRequestDispatcher("/WEB-INF/pages/install/createlicense.jsp").forward(request, response); return; } //save valid license Installation install = Installation.refreshInstallation(); install.setLicense(license); Installation.saveInstallation(install); } } //next step request.getRequestDispatcher("/WEB-INF/pages/install/createmq.jsp").forward(request, response); }
From source file:com.alfaariss.oa.sso.web.profile.web.WebProfile.java
private void handleStartPage(HttpServletRequest oRequest, HttpServletResponse oResponse) throws SSOException, IOException, ServletException { try {//w w w . j a va2 s . co m String sServletPath = oRequest.getServletPath(); StringBuffer sbServletPath = new StringBuffer(sServletPath); if (!sServletPath.endsWith("/")) sbServletPath.append("/"); sbServletPath.append(UserProfile.PROFILE_ID); RequestDispatcher oDispatcher = oRequest.getRequestDispatcher(sbServletPath.toString()); if (oDispatcher != null) oDispatcher.forward(oRequest, oResponse); else { _systemLogger.fatal("Forward request not supported: " + sbServletPath.toString()); throw new SSOException(SystemErrors.ERROR_INTERNAL); } } catch (SSOException e) { throw e; } }
From source file:Index.RegisterRestaurantImagesServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// ww w . jav a2s. co m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { String ubicacionArchivo = "C:\\Users\\Romina\\Documents\\NetBeansProjects\\QuickOrderWeb\\web\\images"; DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setSizeThreshold(1024); factory.setRepository(new File(ubicacionArchivo)); ServletFileUpload upload = new ServletFileUpload(factory); try { List<FileItem> partes = upload.parseRequest(request); List<String> listImage = (List<String>) request.getSession().getAttribute("listImagen"); if (listImage == null) { listImage = new ArrayList<String>(); } for (FileItem item : partes) { webservice.Restaurante rest = (webservice.Restaurante) request.getSession() .getAttribute("registroUsuario"); File file = new File(ubicacionArchivo, rest.getNickname() + listImage.size() + ".jpg"); item.write(file); System.out.println("name: " + item.getName()); listImage.add(rest.getNickname() + listImage.size() + ".jpg"); } request.getSession().setAttribute("listImagen", listImage); request.getRequestDispatcher("/AltaRestauranteImagen.jsp").forward(request, response); } catch (FileUploadException ex) { System.out.println("Error al subir el archivo: " + ex.getMessage()); request.getRequestDispatcher("/AltaRestauranteImagen.jsp").forward(request, response); } catch (Exception ex) { System.out.println("Error al subir el archivo: " + ex.getMessage()); request.getRequestDispatcher("/AltaRestauranteImagen.jsp").forward(request, response); } } }
From source file:classes.newsserv.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w . j a v a2s.c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, FileUploadException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); // Apache Commons-Fileupload library classes DiskFileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload sfu = new ServletFileUpload(factory); if (!ServletFileUpload.isMultipartContent(request)) { System.out.println("sorry. No file uploaded"); return; } try {// parse request List items = sfu.parseRequest(request); FileItem title = (FileItem) items.get(0); String t = title.getString(); //System.out.println("t=" + t); FileItem news = (FileItem) items.get(1); String n = news.getString(); FileItem date = (FileItem) items.get(2); String d = date.getString(); FileItem time = (FileItem) items.get(3); String ti = time.getString(); FileItem btn = (FileItem) items.get(5); String button = btn.getString(); // get uploaded file FileItem file = (FileItem) items.get(4); if (button.equals("add")) { adminclass x = new adminclass(); if (x.insertnews(t, n, d, ti, file)) { RequestDispatcher regd = request.getRequestDispatcher("news.jsp"); regd.include(request, response); } } else if (button.equals("Select")) {//System.out.println("aval"); adminclass x = new adminclass(); ArrayList al = new ArrayList(); id = Long.parseLong(request.getParameter("txt_id")); al = x.searchnews(id); request.setAttribute("data", al); // out.println("Record Searched"); // id=Long.parseLong(al.get(0).toString()); //System.out.println(id); RequestDispatcher regd = request.getRequestDispatcher("news.jsp"); regd.include(request, response); } else if (button.equals("update")) { adminclass x = new adminclass(); if (x.updatenews(id, t, n, d, ti)) { RequestDispatcher regd = request.getRequestDispatcher("news.jsp"); regd.include(request, response); } } } finally { out.close(); } }
From source file:com.lrodriguez.SVNBrowser.java
private void doSwitchBranch(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws ServletException, IOException { logDebug("dispatching Browser switch branch query"); //List uniqueEntries = getUniqueEntries(request, startDate, endDate); //if(request.getAttribute(ERROR)!= null){ // request.getRequestDispatcher("index.jsp").forward(request, response); // return;/* w w w . j a v a 2 s . c o m*/ //} //uniqueEntries = filterListByCurrentBranch(uniqueEntries, currentBranch); //Collections.sort(uniqueEntries, comparator); session.setAttribute(UNIQUE_ENTRIES, null); request.getRequestDispatcher(INDEX_JSP).forward(request, response); return; }
From source file:com.edgenius.wiki.webapp.servlet.InstallServlet.java
@Override protected void doService(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (checkDowngrade(request, response)) { return;/*from w w w . j a v a 2s. co m*/ } String step = request.getParameter("step"); if (Version.LICENSE_STATUS > 0) { if ("ulicense".equalsIgnoreCase(step)) { //this is from license-expired.jsp - user try to input another license updateLicense(request, response); } else { request.getRequestDispatcher("/WEB-INF/pages/install/license-expired.jsp").forward(request, response); } return; } if ("chglang".equalsIgnoreCase(step)) { String langs[] = request.getParameter("lang").split("_"); Global.DefaultLanguage = langs[0]; Global.DefaultCountry = langs[1]; response.sendRedirect(WebUtil.getHostAppURL()); return; } if (Installation.DONE) { //system already installed, just skip all process request.getRequestDispatcher("/").forward(request, response); return; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //download DB script request String script = request.getParameter("script"); if (!StringUtils.isBlank(script)) { String type = request.getParameter("type"); if ("db".equalsIgnoreCase(script)) { //download DB create script InputStream is = FileUtil .getFileInputStream("classpath:META-INF/meta/" + type + "/" + type + "-create-db.sql"); String buf = IOUtils.toString(is); IOUtils.closeQuietly(is); response.getOutputStream().write(buf.getBytes(Constants.UTF8)); } else if ("tables".equalsIgnoreCase(script)) { //download table create script StringBuffer buf = new StringBuffer(); buf.append("\n\n-- ============= create tables =================\n"); InputStream is = FileUtil .getFileInputStream("classpath:META-INF/meta/" + type + "/" + type + ".ddl"); buf.append(IOUtils.toString(is)); IOUtils.closeQuietly(is); buf.append("\n\n-- ============= initial data =================\n"); is = FileUtil .getFileInputStream("classpath:META-INF/meta/" + type + "/" + type + "-init-tables.sql"); buf.append(IOUtils.toString(is)); IOUtils.closeQuietly(is); buf.append("\n\n-- ============= quartz tables =================\n"); is = FileUtil.getFileInputStream("classpath:META-INF/meta/" + type + "/" + type + "-quartz.sql"); buf.append(IOUtils.toString(is)); IOUtils.closeQuietly(is); response.getOutputStream().write(buf.toString().getBytes(Constants.UTF8)); } return; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Normal installation process Installation install = Installation.refreshInstallation(); loadInitData(request); //this variable is just for user easily to find back default MQ server URL - currently, it is hardcode. request.getSession().setAttribute("mqserverDefaultUrl", MQ_DEFAULT_URL); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Data root if ("dataroot".equalsIgnoreCase(step)) { //show create data root resetContextPath(request); String sysRoot = System.getProperty(DataRoot.rootKey); if (sysRoot != null && sysRoot.trim().length() > 0) { request.setAttribute("sysPropRoot", sysRoot); request.setAttribute("message", "GeniusWiki found " + sysRoot + " is set as your 'geniuswiki.data.root' in the system property. " + "Your data root is able to use this value. Please reset it and restart web server if it is incorrect."); } request.getRequestDispatcher("/WEB-INF/pages/install/createroot.jsp").forward(request, response); } else if ("cdataroot".equalsIgnoreCase(step)) { //create data root String root = System.getProperty(DataRoot.rootKey); if (root == null || root.trim().length() == 0) { root = request.getParameter("root"); } createDataRoot(root, request, response); //this method must after createDataRoot() as it need DataRoot.getRoot() which save in above method //save contextPath, host, port, and server timezone into global.xml updateGlobal(request.getRequestURL().toString(), request.getServletPath()); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Data root } else if ("license".equalsIgnoreCase(step)) { //show create license updateInstallationStatus(install, Installation.STATUS_DATAROOT); request.getRequestDispatcher("/WEB-INF/pages/install/createlicense.jsp").forward(request, response); } else if ("clicense".equalsIgnoreCase(step)) { //create data root createLicense(request, response); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // MQ } else if ("mq".equalsIgnoreCase(step)) { updateInstallationStatus(install, Installation.STATUS_LICENSE); request.getRequestDispatcher("/WEB-INF/pages/install/createmq.jsp").forward(request, response); } else if ("cmq".equalsIgnoreCase(step)) { //create data root createMQServer(request, response); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // DB } else if ("db".equalsIgnoreCase(step)) { updateInstallationStatus(install, Installation.STATUS_MQ); viewDBCreate(request, response); } else if ("cdb".equalsIgnoreCase(step)) { //create data root createDatabase(request, response); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Table } else if ("tables".equalsIgnoreCase(step)) { updateInstallationStatus(install, Installation.STATUS_DB); viewTableCreate(request, response); } else if ("ctables".equalsIgnoreCase(step)) { //create data root createTables(request, response); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // create admin user } else if ("admin".equalsIgnoreCase(step)) { updateInstallationStatus(install, Installation.STATUS_TABLES); request.getRequestDispatcher("/WEB-INF/pages/install/createadmin.jsp").forward(request, response); } else if ("cadmin".equalsIgnoreCase(step)) { //create data root createAdmin(request, response); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Done } else if ("done".equalsIgnoreCase(step)) { installDone(request, response); response.sendRedirect(WebUtil.getHostAppURL()); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Done } else if ("reset".equalsIgnoreCase(step)) { Installation.DONE = true; // possible 3 cases: // * system install not complete // * context is already loaded, // * context reload successed // all possibility just go to home url request.getRequestDispatcher("/").forward(request, response); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Upgrade } else if ("upgrade".equalsIgnoreCase(step)) { //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //!!! There is similar piece code in StartupListener.java, if any bugs found here, please update correspondingly. if (upgrade(request, install)) { installDone(request, response); response.sendRedirect(WebUtil.getHostAppURL()); } else { //there are some error in upgrade checking viewUpgrade(request, response); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Welcome } else { if (Installation.STATUS_DATAROOT.equalsIgnoreCase(install.getStatus())) { request.getRequestDispatcher("/WEB-INF/pages/install/createmq.jsp").forward(request, response); } else if (Installation.STATUS_LICENSE.equalsIgnoreCase(install.getStatus())) { request.getRequestDispatcher("/WEB-INF/pages/install/createlicense.jsp").forward(request, response); } else if (Installation.STATUS_MQ.equalsIgnoreCase(install.getStatus())) { viewDBCreate(request, response); } else if (Installation.STATUS_DB.equalsIgnoreCase(install.getStatus())) { viewTableCreate(request, response); } else if (Installation.STATUS_TABLES.equalsIgnoreCase(install.getStatus())) { request.getRequestDispatcher("/WEB-INF/pages/install/createadmin.jsp").forward(request, response); } else if (Installation.STATUS_UPGRADE.equalsIgnoreCase(install.getStatus())) { viewUpgrade(request, response); } else { resetContextPath(request); request.getRequestDispatcher("/WEB-INF/pages/install/welcome.jsp").forward(request, response); } } }
From source file:com.darksky.seller.SellerServlet.java
/** * Servlet????????/* w ww .j av a 2 s . c om*/ * @param request * @param response * @throws ServletException * @throws IOException * @throws ParseException */ public void sellerHome(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, ParseException { System.out.println(); System.out.println("----------------------sellerHome------------"); request.getSession().removeAttribute("user"); request.getSession().removeAttribute("order"); request.getSession().removeAttribute("shop"); if (!LoginState) { request.getRequestDispatcher("HomeServlet?method=showShops").forward(request, response); return; } String sellerID = request.getParameter("sellerID"); System.out.println("id: " + sellerID); /* ? */ getInfo(sellerID); request.getSession().setAttribute("user", Seller); /* ? */ if (getShop(Seller.getShopID())) { System.out.println(Seller.getShopID() + ""); if (Shop.getState() == 0) { System.out.println(Seller.getShopID() + ""); request.getSession().setAttribute("sellerShop", "0"); } else if (Shop.getState() == 2) { System.out.println(Seller.getShopID() + ""); request.getSession().setAttribute("sellerShop", "2"); } else if (Shop.getState() == 1) { System.out.println(Seller.getShopID() + ""); request.getSession().setAttribute("shop", Shop); request.getSession().setAttribute("sellerShop", "1"); /* ?? */ getOrder(sellerID); request.getSession().setAttribute("orders", SellerOrders); /* ?? */ getDish(sellerID); request.getSession().setAttribute("dish", DishList); } } else { request.getSession().setAttribute("sellerShop", "x"); System.out.println(Seller.getShopID() + "?"); } System.out.println("----------------------sellerHome------------"); System.out.println(); request.getRequestDispatcher(".jsp").forward(request, response); }
From source file:edu.cornell.mannlib.vitro.webapp.controller.SparqlQueryServlet.java
private void doHelp(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { VitroRequest vreq = new VitroRequest(req); OntologyDao daoObj = vreq.getFullWebappDaoFactory().getOntologyDao(); List<Ontology> ontologiesObj = daoObj.getAllOntologies(); ArrayList<String> prefixList = new ArrayList<String>(); if (ontologiesObj != null && ontologiesObj.size() > 0) { for (Ontology ont : ontologiesObj) { prefixList.add(ont.getPrefix() == null ? "(not yet specified)" : ont.getPrefix()); prefixList.add(ont.getURI() == null ? "" : ont.getURI()); }//from w w w . j a va 2 s . c o m } else { prefixList.add("<strong>" + "No Ontologies added" + "</strong>"); prefixList.add("<strong>" + "Load Ontologies" + "</strong>"); } req.setAttribute("prefixList", prefixList); // nac26: 2009-09-25 - this was causing problems in safari on localhost installations because the href did not include the context. The edit.css is not being used here anyway (or anywhere else for that matter) // req.setAttribute("css", "<link rel=\"stylesheet\" type=\"text/css\" href=\""+portal.getThemeDir()+"css/edit.css\"/>"); req.setAttribute("title", "SPARQL Query"); req.setAttribute("bodyJsp", "/admin/sparqlquery/sparqlForm.jsp"); RequestDispatcher rd = req.getRequestDispatcher("/" + Controllers.BASIC_JSP); rd.forward(req, res); }
From source file:at.gv.egiz.bku.online.webapp.UIServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { BindingProcessorManager bindingProcessorManager = (BindingProcessorManager) getServletContext() .getAttribute("bindingProcessorManager"); if (bindingProcessorManager == null) { String msg = "Configuration error: BindingProcessorManager missing!"; log.error(msg);//from w ww .ja v a2 s .c o m resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg); return; } Configuration conf = ((BindingProcessorManagerImpl) bindingProcessorManager).getConfiguration(); if (conf == null) log.error("No configuration"); else MoccaParameterBean.setP3PHeader(conf, resp); Id id = (Id) req.getAttribute("id"); BindingProcessor bindingProcessor = null; if (id == null || !((bindingProcessor = bindingProcessorManager .getBindingProcessor(id)) instanceof HTTPBindingProcessor)) { resp.sendRedirect(expiredPageUrl); return; } MoccaParameterBean parameterBean = new MoccaParameterBean((HTTPBindingProcessor) bindingProcessor); req.setAttribute("moccaParam", parameterBean); String uiPage = MoccaParameterBean.getInitParameter("uiPage", getServletConfig(), getServletContext()); uiPage = parameterBean.getUIPage(uiPage); if (uiPage == null) { uiPage = "applet.jsp"; } RequestDispatcher dispatcher = req.getRequestDispatcher(uiPage); if (dispatcher == null) { log.warn("Failed to get RequestDispatcher for page {}.", uiPage); resp.sendError(HttpServletResponse.SC_NOT_FOUND); } else { dispatcher.forward(req, resp); } }