List of usage examples for javax.servlet.http HttpServletRequest getRequestDispatcher
public RequestDispatcher getRequestDispatcher(String path);
From source file:edu.morgan.server.UploadFileServlet.java
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { // Check that we have a file upload request RequestDispatcher rd;/*from w w w . j av a 2 s. co m*/ response.setContentType("text/html"); isMultipart = ServletFileUpload.isMultipartContent(request); if (!isMultipart) { rd = request.getRequestDispatcher("fail.jsp"); rd.forward(request, response); } try { ServletFileUpload upload = new ServletFileUpload(); response.setContentType("text/plain"); FileItemIterator iterator = upload.getItemIterator(request); while (iterator.hasNext()) { FileItemStream item = iterator.next(); InputStream stream = item.openStream(); this.read(stream); } rd = request.getRequestDispatcher("success.jsp"); rd.forward(request, response); } catch (Exception ex) { throw new ServletException(ex); } }
From source file:org.keycloak.example.OfflineAccessPortalServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try {//from w w w .j av a2 s. c o m if (req.getRequestURI().endsWith("/login")) { storeToken(req); req.getRequestDispatcher("/WEB-INF/pages/loginCallback.jsp").forward(req, resp); return; } String refreshToken = RefreshTokenDAO.loadToken(); String refreshTokenInfo; boolean savedTokenAvailable; if (refreshToken == null) { refreshTokenInfo = "No token saved in database. Please login first"; savedTokenAvailable = false; } else { RefreshToken refreshTokenDecoded = null; refreshTokenDecoded = TokenUtil.getRefreshToken(refreshToken); String exp = (refreshTokenDecoded.getExpiration() == 0) ? "NEVER" : Time.toDate(refreshTokenDecoded.getExpiration()).toString(); refreshTokenInfo = String.format("<p>Type: %s</p><p>ID: %s</p><p>Expires: %s</p>", refreshTokenDecoded.getType(), refreshTokenDecoded.getId(), exp); savedTokenAvailable = true; } req.setAttribute("tokenInfo", refreshTokenInfo); req.setAttribute("savedTokenAvailable", savedTokenAvailable); String customers; if (req.getRequestURI().endsWith("/loadCustomers")) { customers = loadCustomers(req, refreshToken); } else { customers = ""; } req.setAttribute("customers", customers); req.getRequestDispatcher("/WEB-INF/pages/view.jsp").forward(req, resp); } catch (JWSInputException e) { throw new ServletException(e); } }
From source file:es.uma.inftel.blog.servlet.PerfilServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w . jav a 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 { request.setCharacterEncoding("UTF-8"); BaseView baseView = new BaseView(); BaseViewFacade<BaseView> baseViewFacade = new BaseViewFacade<>(postFacade); baseViewFacade.initView(baseView); RequestDispatcher requestDispatcher = request.getRequestDispatcher("perfil.jsp"); String password = request.getParameter("password"); if (password == null) { request.setAttribute("perfilView", baseView); requestDispatcher.forward(request, response); } String email = request.getParameter("email"); Part filePart = request.getPart("avatar"); byte[] avatar = null; if (!filePart.getSubmittedFileName().isEmpty()) { InputStream inputStream = filePart.getInputStream(); avatar = IOUtils.toByteArray(inputStream); } HttpSession session = request.getSession(); Usuario usuario = (Usuario) session.getAttribute("usuario"); modificarUsuario(usuario, password, email, avatar); response.sendRedirect("perfil"); }
From source file:com.silverpeas.authentication.AuthenticationServlet.java
/** * Centralization.//from w w w.jav a 2 s . c o m * * @param request * @param response * @param destination */ private void forward(HttpServletRequest request, HttpServletResponse response, String destination) throws ServletException, IOException { RequestDispatcher dispatcher = request.getRequestDispatcher(destination); dispatcher.forward(request, response); }
From source file:QueryModifier.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { String requestUrl = request.getRequestURL().toString(); String querystr = request.getQueryString(); if (querystr != null) { querystr = querystr + "&inspector-name=Jen&inspector-email=Jenniferq@yahoo.com"; } else {/*from w w w .j a va 2 s . co m*/ querystr = "inspector-name=Jen&inspector-email=Jenniferq@yahoo.com"; } RequestDispatcher dispatcher = request.getRequestDispatcher("/viewPost.jsp?" + querystr); dispatcher.forward(request, response); }
From source file:com.parallax.server.blocklyprop.servlets.ConfirmServlet.java
public void confirmToken(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String token = req.getParameter("token"); String email = req.getParameter("email"); req.setAttribute("token", token == null ? "" : token); req.setAttribute("email", email == null ? "" : email); if (Strings.isNullOrEmpty(token) || Strings.isNullOrEmpty(email)) { req.getRequestDispatcher("WEB-INF/servlet/confirm/confirm.jsp").forward(req, resp); } else {//w w w.jav a2 s . c o m try { if (cloudSessionLocalUserService.doConfirm(email, token)) { // req.getRequestDispatcher("WEB-INF/servlet/confirm/confirmed.jsp").forward(req, resp); showTextilePage(req, resp, ConfirmPage.CONFIRMED); } else { req.setAttribute("invalidToken", "Invalid token"); req.getRequestDispatcher("WEB-INF/servlet/confirm/confirm.jsp").forward(req, resp); } } catch (UnknownUserException ex) { req.setAttribute("invalidToken", "Unknown email"); req.getRequestDispatcher("WEB-INF/servlet/confirm/confirm.jsp").forward(req, resp); } catch (ServerException se) { req.setAttribute("server-error", "Server exception"); req.getRequestDispatcher("WEB-INF/servlet/confirm/confirm.jsp").forward(req, resp); } catch (WrongAuthenticationSourceException ex) { log.warn("Trying to confirm email of non local user!"); req.setAttribute("server-error", "Server exception"); req.getRequestDispatcher("WEB-INF/servlet/confirm/confirm.jsp").forward(req, resp); } } }
From source file:controller.product.renderUpdateProductServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Product product = new Product(); ProductDAO productDAO = new ProductDAO(); String name = request.getParameter("name"); if (productDAO.connect()) { product = productDAO.getProductByName(name); request.setAttribute("product", product); }// w w w . ja v a2 s . c om productDAO.disconnect(); RequestDispatcher rd = request.getRequestDispatcher("adminpages/updateProduct.jsp"); rd.forward(request, response); }
From source file:controller.product.renderUpdateProductServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Product product = new Product(); ProductDAO productDAO = new ProductDAO(); String name = request.getParameter("name"); if (productDAO.connect()) { product = productDAO.getProductByName(name); request.setAttribute("product", product); }/* w ww . j ava 2 s.c o m*/ productDAO.disconnect(); RequestDispatcher rd = request.getRequestDispatcher("adminpages/updateProduct.jsp"); rd.forward(request, response); }
From source file:edu.cornell.mannlib.vitro.webapp.controller.jena.JenaCsv2RdfController.java
private void forwardToFileUploadError(String errrorMsg, HttpServletRequest req, HttpServletResponse response) throws ServletException { VitroRequest vreq = new VitroRequest(req); req.setAttribute("title", "CSV to RDF Error "); req.setAttribute("bodyJsp", "/jsp/fileUploadError.jsp"); req.setAttribute("errors", errrorMsg); RequestDispatcher rd = req.getRequestDispatcher(Controllers.BASIC_JSP); req.setAttribute("css", "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + vreq.getAppBean().getThemeDir() + "css/edit.css\"/>"); try {//from ww w . java2s.c om rd.forward(req, response); } catch (IOException e1) { log.error(e1); throw new ServletException(e1); } return; }
From source file:es.uma.inftel.blog.servlet.PostServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w . j a v 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 { request.setCharacterEncoding("UTF-8"); String tituloP = request.getParameter("tituloPost"); String textoP = request.getParameter("textoPost"); RequestDispatcher rd = request.getRequestDispatcher("/crearPost.jsp"); if (tituloP == null && textoP == null) { BaseView crearPostView = new BaseView(); BaseViewFacade<BaseView> crearPostViewFacade = new BaseViewFacade<>(postFacade); crearPostViewFacade.initView(crearPostView); request.setAttribute("crearPostView", crearPostView); rd.forward(request, response); return; } Usuario usuario = (Usuario) request.getSession().getAttribute("usuario"); Post post = crearPost(tituloP, textoP, usuario); postFacade.create(post); String etiquetas = request.getParameter("etiqueta"); insertarEtiquetas(etiquetas, post); if (!request.getParameter("lat").isEmpty()) { crearMapa(request, post); } //Crea Fotos insertarImagen(request, post); response.sendRedirect("post?id=" + post.getId()); }