List of usage examples for javax.servlet.http HttpServletRequest getRequestDispatcher
public RequestDispatcher getRequestDispatcher(String path);
From source file:com.netcracker.financeapp.controller.spending.SpendingServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ArrayList<String> spendingTypeList = typeService.getSpendingTypeNames(); request.setAttribute("spendingTypeList", spendingTypeList); ArrayList<String> bankCardNumbers = bankCardService.getBankCardNumbers(); request.setAttribute("fromList", bankCardNumbers); ArrayList<String> agentNames = agentService.getAgentNames(); request.setAttribute("toList", agentNames); request.getRequestDispatcher("spending/spendingPage.jsp").forward(request, response); }
From source file:io.github.benas.todolist.web.servlet.todo.CreateTodoServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); User user = (User) session.getAttribute(TodoListUtils.SESSION_USER); String title = request.getParameter("title"); String dueDate = request.getParameter("dueDate"); String priority = request.getParameter("priority"); Todo todo = new Todo(user.getId(), title, false, Priority.valueOf(priority), new Date(dueDate)); todoService.create(todo);/*ww w . jav a 2 s . co m*/ request.getRequestDispatcher("/todos").forward(request, response); }
From source file:org.blanco.gae.blog.BlogServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { //Parse the input form Entry entry = new Entry(); entry.setAuthor(req.getParameter("author")); entry.setEntry(req.getParameter("entry")); entry.setDate(new Date(System.currentTimeMillis())); //store the entry Session session = (Session) ctx.getBean("session"); session.persist(entry);// w w w . j a v a2 s .c o m session.flush(); session.close(); req.setAttribute("entry", entry); //forward to presentation req.getRequestDispatcher("entry_created.jsp").forward(req, resp); }
From source file:io.github.benas.todolist.web.servlet.user.LoginServlet.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String email = request.getParameter("email"); String password = request.getParameter("password"); LoginForm loginForm = new LoginForm(); loginForm.setEmail(email);/* www .j a v a 2 s. co m*/ loginForm.setPassword(password); String nextPage = LOGIN_PAGE; validateCredentials(request, loginForm); if (isInvalid(request)) { request.getRequestDispatcher(nextPage).forward(request, response); return; } if (isInvalidCombination(email, password)) { request.setAttribute("error", resourceBundle.getString("login.error.global.invalid")); } else { HttpSession session = request.getSession(true);//create session User user = userService.getUserByEmail(email); session.setAttribute(TodoListUtils.SESSION_USER, user); nextPage = "/todos"; } request.getRequestDispatcher(nextPage).forward(request, response); }
From source file:com.gigglinggnus.controllers.AdminClockController.java
/** * * @param request servlet request/* ww w .ja va2s . c o 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 { EntityManager em = (EntityManager) request.getSession().getAttribute("em"); String strTime = request.getParameter("systemTime"); LocalDateTime ldTime = LocalDateTime.parse(strTime); Instant instant = ldTime.atZone(ZoneId.systemDefault()).toInstant(); Clock clk = Clock.fixed(instant, ZoneId.systemDefault()); request.getSession().setAttribute("clock", clk); RequestDispatcher rd = request.getRequestDispatcher("/home.jsp"); rd.forward(request, response); }
From source file:com.netcracker.financeapp.controller.type.typeAddServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String typeName = request.getParameter("typeName"); if (request.getParameter("radios") != null) { int typeId = 0; if (request.getParameter("radios").equals("INCOME")) { typeId = typeService.insertIncomeType(typeName); } else if (request.getParameter("radios").equals("SPENDING")) { typeId = typeService.insertSpendingType(typeName); }//www . j av a 2s. co m if (typeId > 0) { request.getRequestDispatcher("templates/success.jsp").forward(request, response); } else { request.getRequestDispatcher("templates/error.jsp").forward(request, response); } } else { request.getRequestDispatcher("templates/error.jsp").forward(request, response); } }
From source file:com.mondospider.spiderlocationapi.SetSpiderLocation.java
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { if (!req.isSecure()) { resp.getWriter()/*from w w w . jav a2 s . co m*/ .println("{\"result:error\", \"reason\":\"SSL secured connection required for updates.\"}"); return; } if (req.getParameter("lat") == null || req.getParameter("lng") == null || req.getParameter("pwd") == 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 { // Get lat/lng Parameters and validate double lat = 0; double lng = 0; try { lat = Double.parseDouble(req.getParameter("lat")); lng = Double.parseDouble(req.getParameter("lng")); } catch (NumberFormatException e) { responseResp.put("result", "error"); responseResp.put("reason", "Parameter lat or log missing or invalid"); resp.getWriter().println(responseResp.toString(2)); return; } String status = req.getParameter("status"); // Update Position updatePosition("spider", lat, lng, 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:org.jtwig.functions.SpringFunctions.java
@JtwigFunction(name = "render") public String render(HttpServletRequest request, @Parameter String url, @Parameter Map<String, String> parameters) throws FunctionException { RenderHttpServletResponse responseWrapper = new RenderHttpServletResponse(); RenderHttpServletRequest builder = new RenderHttpServletRequest(request).to(url).withMethod(GET); for (Map.Entry<String, String> entry : parameters.entrySet()) { builder.withGetParameter(entry.getKey(), entry.getValue()); }/*from www. ja v a 2 s .c o m*/ try { RequestDispatcher requestDispatcher = request.getRequestDispatcher(request.getServletPath()); requestDispatcher.include(builder, responseWrapper); return responseWrapper.toString(); } catch (ServletException | IOException e) { throw new FunctionException(e); } }
From source file:com.ibm.bluemix.samples.HomeServlet.java
/** * Returns information about the files stored in the database to the home.jsp *///from w w w. j a v a2 s. c o m protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("Home Servlet"); try { List<JSONObject> files = db.getResults(); request.setAttribute("files", files); } catch (Exception e) { request.setAttribute("msg", e.getMessage()); request.setAttribute("files", new ArrayList<JSONObject>()); e.printStackTrace(System.err); } response.setContentType("text/html"); response.setStatus(200); request.getRequestDispatcher("/home.jsp").forward(request, response); }
From source file:common.interceptors.MyInterceptor.java
@Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { if (ex != null) { log.error(":(", ex); //trying to show error page Pages errorPage = (Pages) request.getAttribute("error_page"); if (errorPage != null) { request.setAttribute(gallery.web.controller.pages.Config.CURRENT_PAGE_ATTRIBUTE, errorPage); UrlBean url = type.execute(request, response); request.setAttribute(config.getUrlAttribute(), url); request.getRequestDispatcher(config.getTemplateUrl()).forward(request, response); }/* w w w. j a v a2 s. c om*/ } }