List of usage examples for javax.servlet.http HttpServletRequest getRequestDispatcher
public RequestDispatcher getRequestDispatcher(String path);
From source file:com.mkmeier.quickerbooks.ProcessUwcu.java
private void showForm(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { Map<String, List<QbAccount>> accountLists = getAccountLists(); HttpSession session = request.getSession(true); session.setAttribute("lists", accountLists); RequestDispatcher rd = request.getRequestDispatcher("UwcuProcessor.jsp"); rd.forward(request, response);/* w w w .ja va 2s .c o m*/ }
From source file:Movies.SearchMovie.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w ww. j a va 2s . 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 { String search = request.getParameter("searchMovie"); search = URLEncoder.encode(search, "UTF-8"); URL url = new URL("http://www.omdbapi.com/?i=" + search); ObjectMapper mapper = new ObjectMapper(); Map<String, Object> map = mapper.readValue(url, Map.class); request.setAttribute("movieMap", map); request.getRequestDispatcher("movie.jsp").forward(request, response); }
From source file:com.example.getstarted.basicactions.UpdateBookServlet.java
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { BookDao dao = (BookDao) this.getServletContext().getAttribute("dao"); try {//from ww w . jav a2s . c om Book book = dao.readBook(Long.decode(req.getParameter("id"))); req.setAttribute("book", book); req.setAttribute("action", "Edit"); req.setAttribute("destination", "update"); req.setAttribute("page", "form"); req.getRequestDispatcher("/base.jsp").forward(req, resp); } catch (Exception e) { throw new ServletException("Error loading book for editing", e); } }
From source file:com.jyhon.servlet.audit.AuditUserServlet.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //?/*from w w w .j av a 2 s.c o m*/ String pathTemp = InitFileFolder(); List<FileItem> items = getFileItems(request, pathTemp); UserEntity userEntity = getUserEntity(items); UserEntityService userEntityService = new UserEntityServiceImpl(); Integer result = userEntityService.changeEntityStatus(userEntity); request.getRequestDispatcher("main/auditUserApply.jsp").forward(request, response); }
From source file:dk.statsbiblioteket.doms.licensemodule.servlets.ConfigurationServlet.java
private void returnFormPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { RequestDispatcher dispatcher = request.getRequestDispatcher("configuration.jsp"); dispatcher.forward(request, response); return;//from www .jav a 2 s.co m }
From source file:com.mondospider.spiderlocationapi.SetSpiderStatus.java
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { if (!req.isSecure()) { resp.getWriter()//ww w . j ava 2s.c om .println("{\"result:error\", \"reason\":\"SSL secured connection required for updates.\"}"); return; } if (req.getParameter("status") == null) { //Display Error&Help try { req.getRequestDispatcher("/index.html").forward(req, resp); } catch (ServletException e) { resp.getWriter().println("{\"result:error\", \"reason\":\"Forward failed\"}"); e.printStackTrace(); return; } } // Permission Check String key = req.getParameter("pwd"); if (!isSecretKeyTrue(key)) { // accessDenied resp.getWriter().println("{\"result:error\", \"reason\":\"Wrong Key\"}"); return; } try { String status = req.getParameter("status"); // Update Position updateStatus(status); responseResp.put("result", "success"); responseResp.put("updated_on", new Date()); resp.setContentType("text/plain"); resp.getWriter().println(responseResp.toString(2)); return; } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } resp.sendRedirect("/index.html"); }
From source file:dk.dma.msiproxy.web.MessageDetailsServlet.java
/** * Generates a PDF file containing the MSI message details * @param request the HTTP servlet request * @param response the HTTP servlet response *///w w w. j a v a 2 s .c o m private void generatePdfFile(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { //Capture the content for this request ContentCaptureServletResponse capContent = new ContentCaptureServletResponse(response); request.getRequestDispatcher(DETAILS_JSP_FILE).include(request, capContent); // Check if there is content. Could be a redirect... if (!capContent.hasContent()) { return; } try { // Clean up the response HTML to a document that is readable by the XHTML renderer. String content = capContent.getContent(); Document xhtmlContent = cleanHtml(content); long t0 = System.currentTimeMillis(); String baseUri = app.getBaseUri(); log.info("Generating PDF for " + baseUri); ITextRenderer renderer = new ITextRenderer(); renderer.setDocument(xhtmlContent, baseUri); renderer.layout(); response.setContentType("application/pdf"); if (StringUtils.isNotBlank(request.getParameter("attachment"))) { response.setHeader("Content-Disposition", "attachment; filename=" + request.getParameter("attachment")); } OutputStream browserStream = response.getOutputStream(); renderer.createPDF(browserStream); log.info("Completed PDF generation in " + (System.currentTimeMillis() - t0) + " ms"); } catch (DocumentException e) { throw new ServletException(e); } }
From source file:edu.harvard.hul.ois.pds.ws.PDSWebService.java
public static void printError(HttpServletRequest req, HttpServletResponse res, String message, Throwable e) { HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper(req); wrapper.setAttribute("message", message); wrapper.setAttribute("pdsUrl", req.getContextPath()); wrapper.setAttribute("exception", e); wrapper.setAttribute("req", req); RequestDispatcher rd = req.getRequestDispatcher("/api-error.jsp?"); try {//from w ww . j a v a2 s. c o m rd.forward(req, res); } catch (Exception e1) { e1.printStackTrace(); } }
From source file:com.google.publicalerts.cap.validator.CapValidatorServlet.java
private void render(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setAttribute("analyticsId", System.getProperty(ValidatorUtil.GOOGLE_ANALYTICS_ID)); resp.setCharacterEncoding("UTF-8"); resp.setContentType("text/html"); ValidatorUtil.addNoCachableHeaders(resp); resp.setStatus(HttpServletResponse.SC_OK); req.getRequestDispatcher("/validator.jsp").include(req, resp); }
From source file:controller.deleteGame.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* ww w. j av a 2 s . 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"); try (PrintWriter out = response.getWriter()) { String Code = request.getParameter("Code"); Check c = new Check(); c.setCode(Code); int i = c.deleteGame(); if (i > 0) { RequestDispatcher rd = request.getRequestDispatcher("viewGames.jsp"); request.setAttribute("return", "Data deleted successfully."); rd.forward(request, response); } else { RequestDispatcher rd = request.getRequestDispatcher("deleteGame.jsp"); request.setAttribute("return", "Unable to delete data."); rd.forward(request, response); } } }