@Override public void forward(String path) throws ServletException, IOException { this.request.getRequestDispatcher(path).forward(this.request, this.response); }
/** * Forward to page path relative to the root of the ServletContext. */ public static boolean forwardAbsolute(final ServletContext context, final ServletRequest request, final ServletResponse response, final String resource) throws IOException, ServletException { RequestDispatcher dispatcher = context.getRequestDispatcher(resource); if (dispatcher != null) { dispatcher.forward(request, response); return true; } return false; }
public class AccountServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { List<Account> accounts = getAccountListFromSomewhere(); String url="..."; //relative url for display jsp page ServletContext sc = getServletContext(); RequestDispatcher rd = sc.getRequestDispatcher(url); request.setAttribute("accountList", accounts ); rd.forward(request, response); } }
LOG.debug("No failure URL set, sending 401 Unauthorized error"); LOG.debug("Forwarding to " + targetUrl); request.getRequestDispatcher(targetUrl).forward(request, response); } else { response.addHeader("Error", exception.getLocalizedMessage());
/** * 페이지를 전환한다. * * @param request * 요청 * @param response * 응답 * @param path * 경로 * @throws Exception * 예외 */ protected void dispatch(HttpServletRequest request, HttpServletResponse response, String path) throws Exception { logger.debug("dispatch path: ", path); RequestDispatcher dispatcher = servletConfig.getServletContext().getRequestDispatcher(path); dispatcher.forward(request, response); }
/** * Forward the request to a page which renders IDP selection page for the user. The URL for redirect * and param for IDP selection are included as request attributes under keys with constant names * RETURN_URL and RETURN_PARAM. * * @param request request object * @param response response object * @param responseURL base for the return URL * @param returnParam parameter name to send the IDP entityId in * @throws IOException in case forwarding to the selection page fails * @throws ServletException in case forwarding to the selection page fails */ protected void sendIDPSelection(HttpServletRequest request, HttpServletResponse response, String responseURL, String returnParam) throws IOException, ServletException { // Store the value request.setAttribute(RETURN_URL, responseURL); request.setAttribute(RETURN_PARAM, returnParam); String path = getIdpSelectionPath(); log.debug("Initializing IDP Discovery selection page at {} with return url {}", path, responseURL); request.getRequestDispatcher(path).forward(request, response); }
public class YourServlet extends HttpServlet{ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException{ String search = request.getParameter("search"); if (search != null) { request.setAttribute("search", search); RequestDispatcher rd = request.getRequestDispatcher("Content"); rd.forward(request, response); } } }
HttpServletResponse response = (HttpServletResponse) messageInfo.getResponseMessage(); if ("include".equals(request.getParameter("dispatch"))) { if ("jsf".equals(request.getParameter("tech"))) { target = "/include.jsf"; } else if ("jsfcdi".equals(request.getParameter("tech"))) { target = "/include-cdi.jsf"; request.getRequestDispatcher(target) .include(request, response); request.getRequestDispatcher(target) .forward(request, response);
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // fetch the username that was sent in the request String username = request.getParameter("username"); // TODO: verify if the username is taken in the database // based on the results set the value request.setAttribute("isUsernameTaken", "true"); RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/register.jsp"); dispatcher.forward(request, response); }
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setAttribute("myDate", new Date()); request.getRequestDispatcher("/WEB-INF/index.jsp").forward(request, response); }
protected void validateParamsAndContinue(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { for (Map.Entry<String, String[]> entry : request.getParameterMap().entrySet()) { if (entry.getValue() != null && entry.getValue().length >0) { for (String s : entry.getValue()) { if (hasText(s) && s.contains(NULL_STRING)) { response.setStatus(400); request.setAttribute("error_message_code", "request.invalid_parameter"); request.getRequestDispatcher("/error").forward(request,response); return; } } } } chain.doFilter(request, response); }
private void forwardToOriginalPage(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String redirectUri = request.getParameter(REDIRECT_URI_PARAM); String method = request.getParameter(METHOD_PARAM); HttpServletRequest oldRequest = new MethodAndParametersChangeHttpServletRequest( request, method, HttpServletRequestUtils.filterParametersMap(request.getParameterMap(), filteredParameters)); RequestDispatcher dispatch = request.getRequestDispatcher(redirectUri); dispatch.forward(oldRequest, response); }
request.setAttribute("typedEntitySection", typedEntitySection); wrapper.getRequestDispatcher(wrapper.getServletPath()).forward(wrapper, response); return true;
requestMock.setAttribute(REQUEST_DISPATCHER_REQUEST, true); requestMock.removeAttribute(REQUEST_DISPATCHER_REQUEST); dispatcher.forward(requestMock, mockResponse);
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) servletRequest; String contextPath = httpRequest.getContextPath(); String requestURI = httpRequest.getRequestURI(); requestURI = StringUtils.substringAfter(requestURI, contextPath); if (StringUtils.equals("/", requestURI)) { requestURI = "/index.html"; } String newURI = "/dist" + requestURI; log.debug("Dispatching to URI: {}", newURI); servletRequest.getRequestDispatcher(newURI).forward(servletRequest, servletResponse); } }
protected void forwardToErrorPage(RequestContext context) throws SecurityProviderException, IOException { HttpServletRequest request = context.getRequest(); HttpServletResponse response = context.getResponse(); String errorPageUrl = getErrorPageUrl(); response.setStatus(HttpServletResponse.SC_FORBIDDEN); logger.debug("Forwarding to error page at {}, with 403 FORBIDDEN status", errorPageUrl); RequestDispatcher dispatcher = request.getRequestDispatcher(errorPageUrl); try { dispatcher.forward(request, response); } catch (ServletException e) { throw new SecurityProviderException(e.getMessage(), e); } }
private void redirectTo(final Request request, final Response response, final String url) { try { this.log.debug("redirecting to: {}", url); final ServletContext servletContext = this.context.getServletContext(); final RequestDispatcher disp = servletContext.getRequestDispatcher(url); disp.forward(request.getRequest(), response); } catch (IOException e) { this.log.error(e.getMessage()); this.log.trace("{}", e); throw new RuntimeException(e); } catch (ServletException e) { this.log.error(e.getMessage()); this.log.trace("{}", e); throw new RuntimeException(e); } } }
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{ String prefix =request.getParameter("query"); ArrayList<String> matchingSuggestions = suggestions.getAllPrefixMatches(prefix); request.setAttribute("suggestions",matchingSuggestions); RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/suggest.jsp"); rd.forward(request,response); }
@Override public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException { try { HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage(); HttpServletResponse response = (HttpServletResponse) messageInfo.getResponseMessage(); if ("include".equals(request.getParameter("dispatch"))) { request.getRequestDispatcher("/includedServlet") .include(request, response); // "Do nothing", required protocol when returning SUCCESS handler.handle(new Callback[] { new CallerPrincipalCallback(clientSubject, (Principal) null) }); // When using includes, the response stays open and the main // resource can also write to the response return SUCCESS; } else { request.getRequestDispatcher("/forwardedServlet") .forward(request, response); // MUST NOT invoke the resource, so CAN NOT return SUCCESS here. return SEND_CONTINUE; } } catch (IOException | ServletException | UnsupportedCallbackException e) { throw (AuthException) new AuthException().initCause(e); } }