List of usage examples for javax.servlet RequestDispatcher forward
public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException;
From source file:in.edu.ssn.servlet.RegisterServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w . j a v a 2s . c om * * @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"); PrintWriter out = response.getWriter(); try { String email = request.getParameter("email"); String password = request.getParameter("password"); // System.out.println(numplate+mobileno); Client client; client = ClientBuilder.newClient(); WebTarget target = client .target("https://api.idolondemand.com/1/api/sync/adduser/v1?store=myparkinglot&email=" + email + "&password=" + password + "&apikey=fa64dd8c-6193-47fd-a4ba-052939805fa4"); String response1 = target.request().get(String.class); org.json.JSONObject jsonObject = new org.json.JSONObject(response1); //JSONArray newJSON = jsonObject.getJSONArray("documents"); String c1n = new String(); //jsonObject = newJSON.getJSONObject(0); c1n = jsonObject.getString("message"); System.out.println(c1n); System.out.println(response); if (c1n != null) { RequestDispatcher rd = request.getRequestDispatcher("/book.html"); rd.forward(request, response); } else { RequestDispatcher rd = request.getRequestDispatcher("/home.html"); rd.include(request, response); } /* TODO output your page here. You may use following sample code. out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet RegisterServlet</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>" + response1 + "</h1>"); out.println("</body>"); out.println("</html>");*/ } finally { out.close(); } }
From source file:com.ibm.bluemix.hack.image.ImageEvaluator.java
/** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse * response)// w ww . jav a2s . c o m */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Part file = request.getPart("image_file"); InputStream is = file.getInputStream(); byte[] buf = IOUtils.toByteArray(is); JSONObject results = analyzeImage(buf); request.setAttribute("results", results); RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/image.jsp"); dispatcher.forward(request, response); }
From source file:edu.lternet.pasta.portal.EventSubscribeServlet.java
/** * The doPost method of the servlet. <br> * /*from w ww. j a v a2 s.c o m*/ * This method is called when a form has its tag value method equals to post. * * @param request * the request send by the client to the server * @param response * the response send by the server to the client * @throws ServletException * if an error occurred * @throws IOException * if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession httpSession = request.getSession(); String uid = (String) httpSession.getAttribute("uid"); if (uid == null || uid.isEmpty()) uid = "public"; String packageId = request.getParameter("packageid"); String targetUrl = request.getParameter("targeturl"); String subscription = "<subscription type=\"eml\"><packageId>" + packageId + "</packageId><url>" + targetUrl + "</url></subscription>"; String message = null; String type = "info"; if (uid.equals("public")) { message = LOGIN_WARNING; type = "warning"; } else { try { EventSubscriptionClient eventClient = new EventSubscriptionClient(uid); String subscriptionId = eventClient.create(subscription); message = String.format("An Event Subscription with identifier '<b>%s</b>' was created.\n", subscriptionId); } catch (Exception e) { handleDataPortalError(logger, e); } } request.setAttribute("subscribemessage", message); request.setAttribute("type", type); RequestDispatcher requestDispatcher = request.getRequestDispatcher(forward); requestDispatcher.forward(request, response); }
From source file:edu.lternet.pasta.portal.ProvenanceGraphServlet.java
/** * The doPost method of the servlet. <br> * /*from w w w .j av a2 s.c o m*/ * This method is called when a form has its tag value method equals to post. * * @param request * the request send by the client to the server * @param response * the response send by the server to the client * @throws ServletException * if an error occurred * @throws IOException * if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { HttpSession httpSession = request.getSession(); String uid = (String) httpSession.getAttribute("uid"); if (uid == null || uid.isEmpty()) uid = "public"; String source = request.getParameter("source"); String derived = request.getParameter("derived"); if ((source != null) && (derived != null)) { request.setAttribute("source", source); request.setAttribute("derived", derived); RequestDispatcher requestDispatcher = request.getRequestDispatcher(forward); requestDispatcher.forward(request, response); } else { throw new UserErrorException("Package identifier is null."); } } catch (Exception e) { handleDataPortalError(logger, e); } }
From source file:net.lightbody.bmp.proxy.jetty.servlet.Forward.java
public void doGet(HttpServletRequest sreq, HttpServletResponse sres) throws ServletException, IOException { String path = (String) sreq.getAttribute("javax.servlet.include.servlet_path"); if (path == null) path = sreq.getServletPath();// w w w.j av a 2 s.co m if (path.length() == 0) { path = (String) sreq.getAttribute("javax.servlet.include.path_info"); if (path == null) path = sreq.getPathInfo(); } String forward = (String) _forwardMap.get(path); if (log.isDebugEnabled()) log.debug("Forward " + path + " to " + forward); if (forward != null) { ServletContext context = getServletContext().getContext(forward); String contextPath = sreq.getContextPath(); if (contextPath.length() > 1) forward = forward.substring(contextPath.length()); RequestDispatcher dispatch = context.getRequestDispatcher(forward); if (dispatch != null) { dispatch.forward(sreq, sres); return; } } sres.sendError(404); }
From source file:controllers.ControladorFotoCoin.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//w ww. j a va 2 s . co m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int idMatch = Integer.parseInt(request.getParameter("idMatch")); String userPath = ""; String UPLOAD_DIRECTORY = "/Users/patriciacuevas/NetBeansProjects/PerfectMatchTis2/web/fotosUsuarios"; if (ServletFileUpload.isMultipartContent(request)) { String pathFile = ""; try { List<FileItem> multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); for (FileItem item : multiparts) { if (!item.isFormField()) { String name = new File(item.getName()).getName(); pathFile = UPLOAD_DIRECTORY + File.separator + name; item.write(new File(pathFile)); } } PmtMatchDTO match = new PmtMatchDTO(); match.setMatId(idMatch); PmtIntercambioFotosDTO intercambio = new PmtIntercambioFotosDTO(); intercambio.setInfRutaUsuarioCoincidente(pathFile); intercambio.setMat(match); intercambio.guardar(intercambio); request.setAttribute("message", "Su foto fue enviada exitosamente"); userPath = "cliente"; } catch (Exception ex) { request.setAttribute("message", "Error al cargar el archivo"); userPath = "enviarFotoCoincidente"; } String url = "WEB-INF/view/" + userPath + ".jspf"; RequestDispatcher rd = request.getRequestDispatcher(url); rd.forward(request, response); } }
From source file:edu.lternet.pasta.portal.MapSearchServlet.java
/** * The doPost method of the servlet. <br> * //from w w w .ja v a2 s .co m * This method is called when a form has its tag value method equals to post. * * @param request * the request send by the client to the server * @param response * the response send by the server to the client * @throws ServletException * if an error occurred * @throws IOException * if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String mapSearchResults = null; HttpSession httpSession = request.getSession(); String uid = (String) httpSession.getAttribute("uid"); if (uid == null || uid.isEmpty()) uid = "public"; String queryText = (String) httpSession.getAttribute("queryText"); mapSearchResults = executeQuery(uid, queryText); request.setAttribute("mapSearchResults", mapSearchResults); RequestDispatcher requestDispatcher = request.getRequestDispatcher(forward); requestDispatcher.forward(request, response); }
From source file:org.myjerry.evenstar.web.controller.PageNotFoundController.java
@Override public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { // extract the request URI // and check to see if this is a blog page URL // if yes - go ahead and display the page String uri = request.getRequestURI(); BlogPost post = this.blogPostService.getPostForURI(uri); if (post != null) { RequestDispatcher dispatcher = request.getRequestDispatcher( "/viewPost.html?postID=" + post.getPostID() + "&blogID=" + post.getBlogID()); dispatcher.forward(request, response); return null; }// w ww . j a v a2 s .co m ModelAndView mav = new ModelAndView(); mav.setViewName(".page.not.found"); return mav; }
From source file:net.swas.explorer.servlet.ms.CheckMSStatus.java
/** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) *//*from w w w .j av a 2 s. c om*/ @SuppressWarnings("unchecked") protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { JSONObject messageJson = new JSONObject(); messageJson.put("action", "status"); this.prod.send(messageJson.toJSONString()); if (FormFieldValidator.isLogin(request.getSession())) { } else { } String revMsg = this.cons.getReceivedMessage(request.getServletContext()); log.info("Received Message :" + revMsg); if (revMsg != null) { JSONParser parser = new JSONParser(); JSONObject revJson = null; try { revJson = (JSONObject) parser.parse(revMsg); String reqStatus = (String) revJson.get("status"); if (reqStatus.equals("0")) { String msStatus = (String) revJson.get("msStatus"); if (msStatus.trim().equals("1")) { request.setAttribute("msStatus", "1"); } else if (msStatus.trim().equals("0")) { request.setAttribute("msStatus", "0"); } } } catch (ParseException e) { e.printStackTrace(); } } RequestDispatcher rd = request.getRequestDispatcher("/msStateUpdate.jsp"); rd.forward(request, response); }
From source file:com.mockey.ui.InjectRealUrlPerServiceServlet.java
/** * /* w w w . j a va2s.c om*/ * * @param req * basic request * @param resp * basic resp * @throws ServletException * basic * @throws IOException * basic */ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { RequestDispatcher dispatch = req.getRequestDispatcher("/inject_realurl.jsp"); dispatch.forward(req, resp); }