List of usage examples for javax.servlet ServletRequest getRequestDispatcher
public RequestDispatcher getRequestDispatcher(String path);
From source file:com.netspective.sparx.util.HttpUtils.java
public static void includeServletResourceContent(Writer writer, HttpServletValueContext vc, String includePath, String valueContextAttrName) throws IOException, ServletException { ServletRequest request = vc.getRequest(); ServletResponse response = vc.getResponse(); RequestDispatcher rd = request.getRequestDispatcher(includePath); if (writer != response.getWriter()) response = new AlternateOutputDestServletResponse(writer, response); request.setAttribute(valueContextAttrName, vc); rd.include(request, response);/* w w w . j av a2s. c om*/ request.removeAttribute(valueContextAttrName); }
From source file:org.jdesigner.platform.web.filter.FilterHelpers.java
/** * This is called by any filter after it determines that a request should be * aborted. It determines whether to do a forward or redirect as specified * in the filter's config, and does it./*w w w.ja v a 2s . c om*/ * * @param redirectTo * The URL to redirect to, if specified. * @param forwardTo * The URL to forward to, if specified. * @param request * The current request. * @param response * The current response. * @throws ServletException * If anything goes wrong. * @throws IOException * If anything goes wrong. */ public static void redirectOrForward(String redirectTo, String forwardTo, ServletRequest request, ServletResponse response) throws ServletException, IOException { log.info("redirectOrForward()..."); if (forwardTo != null) { log.info("forwardTo = " + forwardTo); request.getRequestDispatcher(forwardTo).forward(request, response); } if (redirectTo != null) { log.info("redirectTo = " + redirectTo); ((HttpServletResponse) response).sendRedirect(redirectTo); } log.info("Done"); }
From source file:org.apache.struts2.components.Include.java
public static void include(String aResult, Writer writer, ServletRequest request, HttpServletResponse response) throws ServletException, IOException { String resourcePath = getContextRelativePath(request, aResult); RequestDispatcher rd = request.getRequestDispatcher(resourcePath); if (rd == null) { throw new ServletException("Not a valid resource path:" + resourcePath); }//from w ww .j ava 2s .c om PageResponse pageResponse = new PageResponse(response); // Include the resource rd.include((HttpServletRequest) request, pageResponse); //write the response back to the JspWriter, using the correct encoding. String encoding = getEncoding(); if (encoding != null) { //use the encoding specified in the property file pageResponse.getContent().writeTo(writer, encoding); } else { //use the platform specific encoding pageResponse.getContent().writeTo(writer, null); } }
From source file:com.siriusit.spezg.multilib.jsf.login.LoginBean.java
public String logIn() throws IOException, ServletException { ExternalContext externalContext = context.getExternalContext(); ServletRequest servletRequest = (ServletRequest) externalContext.getRequest(); RequestDispatcher dispatcher = servletRequest.getRequestDispatcher("/j_spring_security_check"); dispatcher.forward((ServletRequest) externalContext.getRequest(), (ServletResponse) externalContext.getResponse()); context.responseComplete();// ww w.j av a 2s . co m return null; }
From source file:org.apache.tapestry.jsp.URLRetriever.java
/** * Invokes the servlet to retrieve the URL. The URL is inserted * into the output (as with//from w w w . ja va 2 s. c o m * {@link RequestDispatcher#include(javax.servlet.ServletRequest, javax.servlet.ServletResponse)}). * * **/ public void insertURL(String servletPath) throws JspException { if (LOG.isDebugEnabled()) LOG.debug("Obtaining Tapestry URL for service " + _serviceName + " at " + servletPath); ServletRequest request = _pageContext.getRequest(); RequestDispatcher dispatcher = request.getRequestDispatcher(servletPath); if (dispatcher == null) throw new JspException(Tapestry.format("URLRetriever.unable-to-find-dispatcher", servletPath)); request.setAttribute(Tapestry.TAG_SUPPORT_SERVICE_ATTRIBUTE, _serviceName); request.setAttribute(Tapestry.TAG_SUPPORT_PARAMETERS_ATTRIBUTE, _serviceParameters); request.setAttribute(Tapestry.TAG_SUPPORT_SERVLET_PATH_ATTRIBUTE, servletPath); try { _pageContext.getOut().flush(); dispatcher.include(request, _pageContext.getResponse()); } catch (IOException ex) { throw new JspException(Tapestry.format("URLRetriever.io-exception", servletPath, ex.getMessage())); } catch (ServletException ex) { throw new JspException(Tapestry.format("URLRetriever.servlet-exception", servletPath, ex.getMessage())); } finally { request.removeAttribute(Tapestry.TAG_SUPPORT_SERVICE_ATTRIBUTE); request.removeAttribute(Tapestry.TAG_SUPPORT_PARAMETERS_ATTRIBUTE); request.removeAttribute(Tapestry.TAG_SUPPORT_SERVLET_PATH_ATTRIBUTE); } }
From source file:com.linuxbox.enkive.web.EnkiveServlet.java
/** * Helper function to make forwarding easier. * /* w ww. j a v a 2 s . co m*/ * @param url * @param req * @param resp * @throws ServletException * @throws IOException */ public void forward(String url, ServletRequest req, ServletResponse resp) throws ServletException, IOException { final RequestDispatcher dispatcher = req.getRequestDispatcher(url); dispatcher.forward(req, resp); }
From source file:org.openmrs.web.dwr.DwrFilter.java
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { String uri = ((HttpServletRequest) req).getRequestURI(); uri = uri.replace("/dwr/", "/ms/legacyui/dwr-invoker/"); uri = uri.replace("/ms/call/plaincall/", "/ms/legacyui/dwr-invoker/call/plaincall/"); uri = uri.replace("/" + WebConstants.WEBAPP_NAME, ""); req.getRequestDispatcher(uri).forward(req, res); }
From source file:org.jaffa.util.CasExclusionFilter.java
/** * Implementation of filter operations when it is triggered. This filter skips all subseqwuent filters unless they * are configured with the FORWARD dispatcher * @param request The HTTP request for endpoint access * @param response The HTTP response supplied by the server * @param chain The linear chain of filters * @throws IOException When a filter, endpoint, or server component cannot be accesses * @throws ServletException General exception thrown by a servlet when it encounters difficulty *//*from ww w . j av a2 s .c o m*/ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpServletRequest = (HttpServletRequest) request; String path = httpServletRequest.getServletPath(); String info = StringUtils.defaultString(httpServletRequest.getPathInfo()); RequestDispatcher dispatcher = request.getRequestDispatcher(path + info); if (dispatcher != null) { dispatcher.forward(request, response); } }
From source file:org.compiere.web.AdempiereMonitorFilter.java
/** * Filter// w w w .java2 s . c om * @param request request * @param response response * @param chain chain * @throws IOException * @throws ServletException */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { boolean error = false; String errorPage = "/error.html"; boolean pass = false; try { if (!(request instanceof HttpServletRequest && response instanceof HttpServletResponse)) { request.getRequestDispatcher(errorPage).forward(request, response); return; } HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse resp = (HttpServletResponse) response; // Previously checked HttpSession session = req.getSession(true); Long compare = (Long) session.getAttribute(AUTHORIZATION); if (compare != null && compare.compareTo(m_authorization) == 0) { pass = true; } else if (checkAuthorization(req.getHeader("Authorization"))) { session.setAttribute(AUTHORIZATION, m_authorization); pass = true; } // -------------------------------------------- if (pass) { chain.doFilter(request, response); } else { resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED); resp.setHeader("WWW-Authenticate", "BASIC realm=\"Adempiere Server\""); } return; } catch (Exception e) { log.log(Level.SEVERE, "filter", e); } request.getRequestDispatcher(errorPage).forward(request, response); }
From source file:org.beangle.security.web.access.DefaultAccessDeniedHandler.java
public void handle(ServletRequest request, ServletResponse response, AccessDeniedException exception) throws IOException, ServletException { if (null != location) { }//from ww w . ja v a2 s . c o m if (errorPage != null) { // Put exception into request scope (perhaps of use to a view) ((HttpServletRequest) request).setAttribute(ACCESS_DENIED_EXCEPTION_KEY, exception); // Perform RequestDispatcher "forward" RequestDispatcher rd = request.getRequestDispatcher(errorPage); rd.forward(request, response); } if (!response.isCommitted()) { // Send 403 (we do this after response has been written) ((HttpServletResponse) response).sendError(HttpServletResponse.SC_FORBIDDEN, exception.getMessage()); } }