List of usage examples for javax.servlet RequestDispatcher INCLUDE_PATH_INFO
String INCLUDE_PATH_INFO
To view the source code for javax.servlet RequestDispatcher INCLUDE_PATH_INFO.
Click Source Link
From source file:net.yacy.http.servlets.YaCyDefaultServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String pathInfo;//from www . ja v a2 s. c o m Enumeration<String> reqRanges = null; boolean included = request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI) != null; if (included) { pathInfo = (String) request.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO); if (pathInfo == null) { pathInfo = request.getPathInfo(); } } else { pathInfo = request.getPathInfo(); // Is this a Range request? reqRanges = request.getHeaders(HeaderFramework.RANGE); if (!hasDefinedRange(reqRanges)) { reqRanges = null; } } String pathInContext = pathInfo == null ? "/" : pathInfo; // this is the path of the resource in _resourceBase (= path within htroot respective htDocs) boolean endsWithSlash = pathInContext.endsWith(URIUtil.SLASH); // Find the resource Resource resource = null; try { // Look for a class resource boolean hasClass = false; if (reqRanges == null && !endsWithSlash) { final int p = pathInContext.lastIndexOf('.'); if (p >= 0) { String pathofClass = pathInContext.substring(0, p) + ".class"; Resource classresource = _resourceBase.addPath(pathofClass); // Does a class resource exist? if (classresource != null && classresource.exists() && !classresource.isDirectory()) { hasClass = true; } } } // find resource resource = getResource(pathInContext); if (!hasClass && (resource == null || !resource.exists()) && !pathInContext.contains("..")) { // try to get this in the alternative htDocsPath resource = Resource.newResource(new File(_htDocsPath, pathInContext)); } if (ConcurrentLog.isFine("FILEHANDLER")) { ConcurrentLog.fine("FILEHANDLER", "YaCyDefaultServlet: uri=" + request.getRequestURI() + " resource=" + resource); } // Handle resource if (!hasClass && (resource == null || !resource.exists())) { if (included) { throw new FileNotFoundException("!" + pathInContext); } response.sendError(HttpServletResponse.SC_NOT_FOUND); } else if (!resource.isDirectory()) { if (endsWithSlash && pathInContext.length() > 1) { String q = request.getQueryString(); pathInContext = pathInContext.substring(0, pathInContext.length() - 1); if (q != null && q.length() != 0) { pathInContext += "?" + q; } response.sendRedirect(response .encodeRedirectURL(URIUtil.addPaths(_servletContext.getContextPath(), pathInContext))); } else { if (hasClass) { // this is a YaCy servlet, handle the template handleTemplate(pathInfo, request, response); } else { if (included || passConditionalHeaders(request, response, resource)) { sendData(request, response, included, resource, reqRanges); } } } } else { // resource is directory String welcome; if (!endsWithSlash) { StringBuffer buf = request.getRequestURL(); synchronized (buf) { int param = buf.lastIndexOf(";"); if (param < 0) { buf.append('/'); } else { buf.insert(param, '/'); } String q = request.getQueryString(); if (q != null && q.length() != 0) { buf.append('?'); buf.append(q); } response.setContentLength(0); response.sendRedirect(response.encodeRedirectURL(buf.toString())); } } // else look for a welcome file else if (null != (welcome = getWelcomeFile(pathInContext))) { ConcurrentLog.fine("FILEHANDLER", "welcome={}" + welcome); // Forward to the index RequestDispatcher dispatcher = request.getRequestDispatcher(welcome); if (dispatcher != null) { if (included) { dispatcher.include(request, response); } else { dispatcher.forward(request, response); } } } else { if (included || passConditionalHeaders(request, response, resource)) { sendDirectory(request, response, resource, pathInContext); } } } } catch (IllegalArgumentException e) { ConcurrentLog.logException(e); if (!response.isCommitted()) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } } finally { if (resource != null) { resource.close(); } } }
From source file:org.ireland.jnetty.jsp.JspServletComposite.java
@Override public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String jspUri = request.getRequestURI(); if (jspUri == null) { // JSP specified via <jsp-file> in <servlet> declaration and supplied through // custom servlet container code jspUri = (String) request.getAttribute(Constants.JSP_FILE); }//from ww w . j a v a2 s . com if (jspUri == null) { /* * Check to see if the requested JSP has been the target of a RequestDispatcher.include() */ jspUri = (String) request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH); if (jspUri != null) { /* * Requested JSP has been target of RequestDispatcher.include(). Its path is assembled from the relevant * javax.servlet.include.* request attributes */ String pathInfo = (String) request.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO); if (pathInfo != null) { jspUri += pathInfo; } } else { /* * Requested JSP has not been the target of a RequestDispatcher.include(). Reconstruct its path from the * request's getServletPath() and getPathInfo() */ jspUri = request.getServletPath(); String pathInfo = request.getPathInfo(); if (pathInfo != null) { jspUri += pathInfo; } } } if (debug) { log.debug("JspEngine --> " + jspUri); log.debug("\t ServletPath: " + request.getServletPath()); log.debug("\t PathInfo: " + request.getPathInfo()); log.debug("\t RealPath: " + context.getRealPath(jspUri)); log.debug("\t RequestURI: " + request.getRequestURI()); log.debug("\t QueryString: " + request.getQueryString()); } try { boolean isPreCompile = isPreCompile(request); //??JSPServlet serviceJspFile(request, response, jspUri, isPreCompile); } catch (RuntimeException e) { throw e; } catch (ServletException e) { throw e; } catch (IOException e) { throw e; } catch (Throwable e) { ExceptionUtils.handleThrowable(e); throw new ServletException(e); } }
From source file:org.ireland.jnetty.webapp.RequestDispatcherImpl.java
private void doInclude(HttpServletRequest request, HttpServletResponse response, HttpInvocation invocation) throws ServletException, IOException { //Wrap the request IncludeRequest wrequest = new IncludeRequest(request, response, invocation); // If we have already been include previously, then keep using the established // original value. Otherwise, this is the first include and we need to establish the values. // Note: the established value on the original request for pathInfo and // for queryString is allowed to be null, but cannot be null for the other values. if (request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI) == null) { // ?Include, wrequest.setAttribute(RequestDispatcher.INCLUDE_REQUEST_URI, request.getRequestURI()); wrequest.setAttribute(RequestDispatcher.INCLUDE_CONTEXT_PATH, request.getContextPath()); wrequest.setAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH, request.getServletPath()); wrequest.setAttribute(RequestDispatcher.INCLUDE_PATH_INFO, request.getPathInfo()); wrequest.setAttribute(RequestDispatcher.INCLUDE_QUERY_STRING, request.getQueryString()); }//from w w w. j a v a2 s .c om boolean isValid = false; try { invocation.getFilterChainInvocation().service(wrequest, response); isValid = true; } finally { if (request.getAsyncContext() != null) { // An async request was started during the forward, don't close the // response as it may be written to during the async handling return; } // server/106r, ioc/0310 if (isValid) { finishResponse(response); } } }
From source file:org.raptorjs.templating.rhino.servlet.RaptorTemplatesServlet.java
@Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String templateUri = (String) request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH); if (templateUri != null) { /*/*from ww w.j a v a 2 s.c om*/ * Requested template has been target of * RequestDispatcher.include(). Its path is assembled from the * relevant javax.servlet.include.* request attributes */ String pathInfo = (String) request.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO); if (pathInfo != null) { templateUri += pathInfo; } } else { /* * Requested template has not been the target of a * RequestDispatcher.include(). Reconstruct its path from the * request's getServletPath() and getPathInfo() */ templateUri = request.getServletPath(); String pathInfo = request.getPathInfo(); if (pathInfo != null) { templateUri += pathInfo; } } if (log.isDebugEnabled()) { log.debug("Raptor Templating Enging --> " + templateUri); log.debug("\t ServletPath: " + request.getServletPath()); log.debug("\t PathInfo: " + request.getPathInfo()); log.debug("\t RealPath: " + context.getRealPath(templateUri)); log.debug("\t RequestURI: " + request.getRequestURI()); log.debug("\t QueryString: " + request.getQueryString()); } try { serviceRhtmlFile(request, response, templateUri); } catch (RuntimeException e) { throw e; } catch (ServletException e) { throw e; } catch (IOException e) { throw e; } catch (Throwable e) { throw new ServletException(e); } }