Package javax.servlet

Examples of javax.servlet.RequestDispatcher


    /**
     * @see org.apache.sling.api.scripting.SlingScriptHelper#forward(org.apache.sling.api.resource.Resource, org.apache.sling.api.request.RequestDispatcherOptions)
     */
    public void forward(Resource resource, RequestDispatcherOptions options) {
        final RequestDispatcher dispatcher = getRequest().getRequestDispatcher(
            resource, options);

        if (dispatcher != null) {
            try {
                dispatcher.forward(getRequest(), getResponse());
            } catch (IOException ioe) {
                throw new SlingIOException(ioe);
            } catch (ServletException se) {
                throw new SlingServletException(se);
            }
View Full Code Here


    /**
     * @see org.apache.sling.api.scripting.SlingScriptHelper#include(org.apache.sling.api.resource.Resource, org.apache.sling.api.request.RequestDispatcherOptions)
     */
    public void include(Resource resource, RequestDispatcherOptions options) {
        final RequestDispatcher dispatcher = getRequest().getRequestDispatcher(
            resource, options);

        if (dispatcher != null) {
            try {
                dispatcher.include(getRequest(), getResponse());
            } catch (IOException ioe) {
                throw new SlingIOException(ioe);
            } catch (ServletException se) {
                throw new SlingServletException(se);
            }
View Full Code Here

                // include the index resource with no suffix and selectors !
                RequestDispatcherOptions rdo = new RequestDispatcherOptions();
                rdo.setReplaceSuffix("");
                rdo.setReplaceSelectors("");

                RequestDispatcher dispatcher;
                if (index.indexOf('.') < 0) {
                    String filePath = fileRes.getPath() + ".html";
                    dispatcher = request.getRequestDispatcher(filePath, rdo);
                } else {
                    dispatcher = request.getRequestDispatcher(fileRes, rdo);
                }

                setHeaders(fileRes, response);

                dispatcher.include(request, response);
                return;
            }
        }

        if (index) {
View Full Code Here

    /**
     * Tests that the RequestDispatcher is wrapped.
     */
    @Test
    public void testGetRequestDispatcher() {
        final RequestDispatcher rd = context.mock(RequestDispatcher.class);
        final ServletContext ctx = context.mock(ServletContext.class);
        context.checking(new Expectations() {{
            oneOf(ctx).getRequestDispatcher("foo.jsp");
            will(returnValue(rd));
           
        }});
       
        ExternalServletContextWrapper wrapper = new ExternalServletContextWrapper(ctx);
        RequestDispatcher dispatcher = wrapper.getRequestDispatcher("foo.jsp");
       
        assertTrue(dispatcher instanceof RequestDispatcherWrapper);
        assertEquals(rd, ((RequestDispatcherWrapper)dispatcher).getDelegate());
    }
View Full Code Here

    InputStream xmlSourceFile = xmlResource.adaptTo(InputStream.class);
    if (xmlSourceFile != null)
      return xmlSourceFile;
   
    // The source is dynamically generated
    RequestDispatcher dispatcher = request.getRequestDispatcher(xmlPath);
    SlingGeneratorServletOutputStream output = new SlingGeneratorServletOutputStream();
    ServletResponse newResponse = new SlingGeneratorServletResponse(response, output);
    dispatcher.include(request, newResponse);
    byte[] bytes = output.toByteArray();
    if (bytes.length > 0)
      return new ByteArrayInputStream(bytes);
   
    return null;
View Full Code Here

public class JspDispatchServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        RequestDispatcher rd = getServletContext().getRequestDispatcher(req.getRequestURI());
        req.setAttribute("org.apache.catalina.jsp_file", req.getRequestURI());
       
        // Wrap ServletPath with an empty value to avoid Guice's null getServletPath() bug from within a filter/servlet chain
        HttpServletRequest wrapped = new HttpServletRequestWrapper(req) {
            public String getServletPath() {
                return "";
            }
        };

        rd.include(wrapped, resp);
    }
View Full Code Here

    }
    resp.flushBuffer();
  }

  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    RequestDispatcher rd = req.getRequestDispatcher("/w3login/login"); //$NON-NLS-1$
    rd.forward(req, resp);
  }
View Full Code Here

        }

        this.forwardURL = uri;
        log.debug("Forwarding to: " + uri);

        RequestDispatcher dispatcher = request.getRequestDispatcher(uri);
        dispatcher.forward(request, response);
    }
View Full Code Here

    // TODO(dhanji): check servlet spec to see if the following is legal or not.
    // Need to strip query string if requested...

    for (final ServletDefinition servletDefinition : servletDefinitions) {
      if (servletDefinition.shouldServe(path)) {
        return new RequestDispatcher() {
          public void forward(ServletRequest servletRequest, ServletResponse servletResponse)
              throws ServletException, IOException {
            Preconditions.checkState(!servletResponse.isCommitted(),
                "Response has been committed--you can only call forward before"
                + " committing the response (hint: don't flush buffers)");
View Full Code Here

     * @param path
     */
    protected void forward(final HttpServletRequest request,
            final HttpServletResponse response, final String path) {
        try {
            final RequestDispatcher rd = request.getRequestDispatcher(path);
            rd.forward(request, response);
        }
        catch (final Throwable tr) {
            if (log.isErrorEnabled()) {
                log.error("Cought Exception: " + tr.getMessage());
                log.debug("StackTrace:", tr);
View Full Code Here

TOP

Related Classes of javax.servlet.RequestDispatcher

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.