List of usage examples for javax.servlet.http HttpServletRequest getRequestDispatcher
public RequestDispatcher getRequestDispatcher(String path);
From source file:controller.servlet.PostServlet.java
private void addTopic(HttpServletRequest request, HttpServletResponse response, Post post) throws ServletException, IOException { PostDAOService postService = PostDAO.getInstance(); if (postService.insertPost(post)) { response.sendRedirect("attach?action=load&id=" + post.getPostID()); } else {//from w w w .j a v a 2s. c om request.setAttribute(Constants.CURRENT_POST, post); request.setAttribute(Constants.MSG_RESULT, "Li"); request.setAttribute(Constants.PAGE, "new-topic"); request.getRequestDispatcher(Constants.URL_HOME).forward(request, response); } }
From source file:com.gigglinggnus.controllers.StudentMakeAppointmentController.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { EntityManager em = (EntityManager) request.getSession().getAttribute("em"); Clock clk = (Clock) (request.getSession().getAttribute("clock")); List<Term> terms = Term.getFutureTerms(em, Instant.now(clk)); List<Exam> exams = terms.stream().flatMap(term -> term.getExams().stream()) .filter(exam -> exam.getStatus() == ExamStatus.PENDING).collect(Collectors.toList()); request.setAttribute("exams", exams); RequestDispatcher rd = request.getRequestDispatcher("/student/make-apmt.jsp"); rd.forward(request, response);//from ww w.j a v a 2s .c om }
From source file:com.juicioenlinea.application.servlets.particular.DemandaServlet.java
private void form(HttpServletRequest request, HttpServletResponse response) { try {/* ww w . ja v a 2 s . c o m*/ request.getRequestDispatcher("crearDemanda.jsp").forward(request, response); } catch (ServletException | IOException ex) { Logger.getLogger(DemandaServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:jeeves.config.springutil.JeevesAccessDeniedHandler.java
@Override public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { if (!response.isCommitted()) { if (matcher != null && matcher.matches(request)) { response.sendError(HttpServletResponse.SC_FORBIDDEN, accessDeniedException.getMessage()); }//from w w w . j a v a2 s. c om if (_errorPage != null) { request.setAttribute(WebAttributes.ACCESS_DENIED_403, accessDeniedException); response.setStatus(HttpServletResponse.SC_FORBIDDEN); final String referer = _escaper.escape(request.getRequestURI()); RequestDispatcher dispatcher = request.getRequestDispatcher(_errorPage + "?referer=" + referer); dispatcher.forward(request, response); } else { response.sendError(HttpServletResponse.SC_FORBIDDEN, accessDeniedException.getMessage()); } } }
From source file:at.ac.univie.isc.asio.insight.ExplorerPageRedirectFilter.java
@Override protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws ServletException, IOException { final String redirect = template.findRedirectTarget(request); final String original = request.getRequestURI(); if (redirect == null) { // skip redirect log.debug(Scope.REQUEST.marker(), "not an explorer request ({}) - skip redirecting", original); chain.doFilter(request, response); return;//from w ww . j a v a 2s .c o m } assert redirect.startsWith("/") : "redirect target is not an absolute path"; final RequestDispatcher dispatcher = request.getRequestDispatcher(redirect); if (dispatcher == null) { // redirect cannot be handled final String message = Pretty.format("no handler for request to <%s> (redirected from <%s>) found", redirect, original); log.debug(Scope.REQUEST.marker(), message); if (!response.isCommitted()) { response.sendError(HttpServletResponse.SC_NOT_FOUND, message); } return; } log.debug(Scope.REQUEST.marker(), "redirect request from {} to {}", original, redirect); dispatcher.forward(request, response); }
From source file:com.gst.infrastructure.security.service.CustomAuthenticationFailureHandler.java
/** * Performs the redirect or forward to the {@code defaultFailureUrl} if set, * otherwise returns a 401 error code./*ww w. j av a2 s.c o m*/ * <p> * If redirecting or forwarding, {@code saveException} will be called to * cache the exception for use in the target view. */ @Override public void onAuthenticationFailure(final HttpServletRequest request, final HttpServletResponse response, final AuthenticationException exception) throws IOException, ServletException { if (this.defaultFailureUrl == null) { this.logger.debug("No failure URL set, sending 401 Unauthorized error"); response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authentication Failed: " + exception.getMessage()); } else { saveException(request, exception); if (this.forwardToDestination) { this.logger.debug("Forwarding to " + this.defaultFailureUrl); request.getRequestDispatcher(this.defaultFailureUrl).forward(request, response); } else { this.logger.debug("Redirecting to " + this.defaultFailureUrl); final String oauthToken = request.getParameter("oauth_token"); request.setAttribute("oauth_token", oauthToken); final String url = this.defaultFailureUrl + "?oauth_token=" + oauthToken; this.redirectStrategy.sendRedirect(request, response, url); } } }
From source file:de.highbyte_le.weberknecht.request.view.WebActionProcessor.java
protected void processJsp(HttpServletRequest request, HttpServletResponse response, View view, Map<String, Object> modelMap, Object action) throws ServletException, IOException { if (log.isDebugEnabled()) log.debug("processJsp() - forward the request to the given view: " + view.getJspFileName()); //add models to request if (modelMap != null) { ModelHelper modelHelper = new ModelHelper(request, servletContext); for (Entry<String, Object> e : modelMap.entrySet()) { modelHelper.set(e.getKey(), e.getValue()); }/*from w w w . jav a 2s . co m*/ } //forward the request to the given view RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/jsp/" + view.getJspFileName()); dispatcher.forward(request, response); }
From source file:com.wibidata.shopping.servlet.SignInServlet.java
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { request.setCharacterEncoding("UTF-8"); final Kiji kiji = (Kiji) getServletContext().getAttribute(KijiContextListener.KIJI_ATTRIBUTE); final String login = request.getParameter("login"); final String password = request.getParameter("password"); if (null == login || login.isEmpty() || null == password || password.isEmpty()) { request.setAttribute("login", login); request.setAttribute("password", password); request.setAttribute("error", "All fields are required."); request.getRequestDispatcher("/WEB-INF/view/SignIn.jsp").forward(request, response); return;//w ww .ja v a 2 s. com } final KijiTable userTable = kiji.openTable("kiji_shopping_user"); final EntityId entityId = userTable.getEntityId(login); final KijiTableReader reader = userTable.openTableReader(); try { // Authenticate the user. KijiDataRequestBuilder drBuilder = KijiDataRequest.builder(); drBuilder.newColumnsDef().add("info", "password").add("info", "name"); KijiDataRequest dataRequest = drBuilder.build(); KijiRowData row = reader.get(entityId, dataRequest); if (!row.containsColumn("info", "password") || !BCrypt.checkpw(password, row.getMostRecentValue("info", "password").toString())) { request.setAttribute("login", login); request.setAttribute("error", "Invalid login or password."); request.getRequestDispatcher("/WEB-INF/view/SignIn.jsp").forward(request, response); return; } request.setAttribute("name", row.getMostRecentValue("info", "name").toString()); } catch (KijiDataRequestException e) { throw new IOException(e); } finally { IOUtils.closeQuietly(reader); ResourceUtils.releaseOrLog(userTable); } // Set the login cookie for the user. request.getSession().setAttribute("login", login); request.getRequestDispatcher("/WEB-INF/view/SignedIn.jsp").forward(request, response); }
From source file:com.gigglinggnus.controllers.AdminMakeAppointmentController.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { EntityManager em = (EntityManager) request.getSession().getAttribute("em"); Clock clk = (Clock) (request.getSession().getAttribute("clock")); List<Term> terms = Term.getFutureTerms(em, Instant.now(clk)); List<Exam> exams = terms.stream().flatMap(term -> term.getExams().stream()) .filter(exam -> exam.getStatus() == ExamStatus.PENDING).collect(Collectors.toList()); request.setAttribute("exams", exams); RequestDispatcher rd = request.getRequestDispatcher("/admin/make-apmt.jsp"); rd.forward(request, response);//from w w w.ja v a 2 s .co m }
From source file:com.krawler.svnwebclient.authorization.impl.CredentialsManager.java
protected void forceCredentialsRequest(HttpServletRequest request, HttpServletResponse response) { request.getSession().setAttribute(CredentialsManager.CREDENTIALS, null); request.getSession().setAttribute(SystemInitializing.ID, null); try {/* w w w.j a v a2s . co m*/ if (ConfigurationProvider.getInstance().isBasicAuth()) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.setHeader("WWW-Authenticate", "BASIC realm=\"" + ConfigurationProvider.getInstance().getBasicRealm() + "\""); response.sendError(401); } else { RequestDispatcher dispatcher = request.getRequestDispatcher(Links.LOGIN); dispatcher.forward(request, response); } } catch (Exception e) { Logger.getLogger(this.getClass()).error(e, e); } }