當前位置: 首頁>>代碼示例>>Java>>正文


Java RequestDispatcher.include方法代碼示例

本文整理匯總了Java中javax.servlet.RequestDispatcher.include方法的典型用法代碼示例。如果您正苦於以下問題:Java RequestDispatcher.include方法的具體用法?Java RequestDispatcher.include怎麽用?Java RequestDispatcher.include使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.servlet.RequestDispatcher的用法示例。


在下文中一共展示了RequestDispatcher.include方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getFileText

import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
public String getFileText( String originalPath, boolean virtual ) throws IOException {
try {
    ServletContextAndPath csAndP = getServletContextAndPath( originalPath, virtual );
    ServletContext context = csAndP.getServletContext();
    String path = csAndP.getPath();

    RequestDispatcher rd =
	context.getRequestDispatcher( path );
    if ( rd == null ) {
	throw new IOException("Couldn't get request dispatcher for path: " + path );
    }
    ByteArrayServletOutputStream basos = new ByteArrayServletOutputStream();
    ResponseIncludeWrapper responseIncludeWrapper =
	new ResponseIncludeWrapper(res, basos );
    rd.include(req, responseIncludeWrapper );

    //We can't assume the included servlet flushed its output
    responseIncludeWrapper.flushOutputStreamOrWriter();
    byte[] bytes = basos.toByteArray();

    //Assume that the default encoding is what was used to encode the bytes. Questionable.
    String retVal = new String( bytes );

    //make an assumption that an empty response is a failure.  This is a problem if a truly empty file 
    //were included, but not sure how else to tell.
    if ( retVal.equals("") ) {
	throw new IOException("Couldn't find file: " + path );
    }
    return retVal;
} catch (ServletException e) {
    throw new IOException("Couldn't include file: " + originalPath + " because of ServletException: " + e.getMessage() );
}
   }
 
開發者ID:c-rainstorm,項目名稱:jerrydog,代碼行數:34,代碼來源:SSIServletExternalResolver.java

示例2: execute

import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
@Override
public CharSequence execute(String path)
        throws Exception {
    String responseString = "";
    if (!isInvalidPath(path)) {
        TemplateContentModelImpl contentModel = contentModel();
        SlingHttpServletRequest request = contentModel.request();
        ResourceResolver resourceResolver = request.getResourceResolver();
        Resource resource = request.getResource();
        if (path != null) {
            path = interpolate(path);
            path = attachSuffixOrPrefix(path, (String) param("prefix"), (String) param("suffix"));
            if (!path.startsWith("/")) {
                path = request.getResource().getPath() + "/" + path;
            }
            path = ResourceUtil.normalize(path);
        }
        ComponentManager componentManager = resourceResolver.adaptTo(ComponentManager.class);
        Resource tmp = request.getResourceResolver().resolve(path);
        String resourceType = interpolate((String) param("resourceType"));

        final RequestDispatcherOptions opts = new RequestDispatcherOptions();
        opts.setForceResourceType(resourceType);
        RequestDispatcher dispatcher;
        if (tmp != null) {
            if (tmp instanceof NonExistingResource) {
                if (resourceType != null) {
                    resource = new IncludeHelperSyntheticResource(request.getResourceResolver(), path, resourceType);
                    opts.remove(RequestDispatcherOptions.OPT_FORCE_RESOURCE_TYPE);
                }
            } else {
                resource = tmp;
            }
        }
        com.day.cq.wcm.api.components.Component component = componentManager.getComponentOfResource(resource);

        dispatcher = request.getRequestDispatcher(resource, opts);
        HttpServletResponse wrappedResponse = contentModel().wrappedResponse();
        dispatcher.include(request, wrappedResponse);
        responseString = wrappedResponse.toString();
    } else {
        LOG.error("{} It is not valid", path);
    }
    return new Handlebars.SafeString(responseString);
}
 
開發者ID:DantaFramework,項目名稱:AEM,代碼行數:46,代碼來源:IncludeResourceHelperFunction.java

示例3: getFileText

import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
public String getFileText(String originalPath, boolean virtual)
        throws IOException {
    try {
        ServletContextAndPath csAndP = getServletContextAndPath(
                originalPath, virtual);
        ServletContext context = csAndP.getServletContext();
        String path = csAndP.getPath();
        RequestDispatcher rd = context.getRequestDispatcher(path);
        if (rd == null) {
            throw new IOException(
                    "Couldn't get request dispatcher for path: " + path);
        }
        ByteArrayServletOutputStream basos =
            new ByteArrayServletOutputStream();
        ResponseIncludeWrapper responseIncludeWrapper =
            new ResponseIncludeWrapper(context, req, res, basos);
        rd.include(req, responseIncludeWrapper);
        //We can't assume the included servlet flushed its output
        responseIncludeWrapper.flushOutputStreamOrWriter();
        byte[] bytes = basos.toByteArray();

        //Assume platform default encoding unless otherwise specified
        String retVal;
        if (inputEncoding == null) {
            retVal = new String( bytes );
        } else {
            retVal = new String (bytes, inputEncoding);
        }

        //make an assumption that an empty response is a failure. This is
        // a problem
        // if a truly empty file
        //were included, but not sure how else to tell.
        if (retVal.equals("") && !req.getMethod().equalsIgnoreCase(
                org.apache.coyote.http11.Constants.HEAD)) {
            throw new IOException("Couldn't find file: " + path);
        }
        return retVal;
    } catch (ServletException e) {
        throw new IOException("Couldn't include file: " + originalPath
                + " because of ServletException: " + e.getMessage());
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:44,代碼來源:SSIServletExternalResolver.java

示例4: doInterpret

import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
private void doInterpret(String requestURL,Map<String, Object> variables, OutputStream output) throws IOException, ServletException {
 	/**
      * 創建ServletContext對象,用於獲取RequestDispatcher對象
      */
     ServletContext sc = request.getSession().getServletContext();
     /**
      * 根據傳過來的相對文件路徑,生成一個reqeustDispatcher的包裝類
      */
     RequestDispatcher rd = sc.getRequestDispatcher(requestURL);
     /**
      * 創建一個ByteArrayOutputStream的字節數組輸出流,用來存放輸出的信息
      */
     final ByteArrayOutputStream baos = new ByteArrayOutputStream();
      
     /**
      * ServletOutputStream是抽象類,必須實現write的方法
      */
     final ServletOutputStream outputStream = new ServletOutputStream(){
         
         public void write(int b) throws IOException {
             /**
              * 將指定的字節寫入此字節輸出流
              */
             baos.write(b);
         }

	@SuppressWarnings("unused")
public boolean isReady() {
		return false;
	}

     }; 
     /**
      * 通過現有的 OutputStream 創建新的 PrintWriter
      * OutputStreamWriter 是字符流通向字節流的橋梁:可使用指定的 charset 將要寫入流中的字符編碼成字節
      */
     final PrintWriter pw = new PrintWriter(new OutputStreamWriter(baos, config.getOutputEncoding() ),true);
     /**
      * 生成HttpServletResponse的適配器,用來包裝response
      */
     HttpServletResponse resp = new HttpServletResponseWrapper(response){
         /**
          * 調用getOutputStream的方法(此方法是ServletResponse中已有的)返回ServletOutputStream的對象
          * 用來在response中返回一個二進製輸出對象
          * 此方法目的是把源文件寫入byteArrayOutputStream
          */
         public ServletOutputStream getOutputStream(){
             return outputStream;
         }
          
         /**
          * 再調用getWriter的方法(此方法是ServletResponse中已有)返回PrintWriter的對象
          * 此方法用來發送字符文本到客戶端
          */
         public PrintWriter getWriter(){
             return pw;
         }
     }; 
     /**
      * 在不跳轉下訪問目標jsp。 就是利用RequestDispatcher.include(ServletRequest request,
      * ServletResponse response)。 該方法把RequestDispatcher指向的目標頁麵寫到response中。
      */
     rd.include(request, resp);
     pw.flush();
     /**
      * 使用ByteArrayOutputStream的writeTo方法來向文本輸出流寫入數據,這也是為什麽要使用ByteArray的一個原因
      */
     baos.writeTo(output);
 }
 
開發者ID:vindell,項目名稱:docx4j-template,代碼行數:70,代碼來源:JspTemplateImpl.java

示例5: processRequest

import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    RequestDispatcher rd = request.getRequestDispatcher("JSP/RessurserM11.jsp");
        rd.include(request, response);    
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:16,代碼來源:RessurserM11.java

示例6: processRequest

import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs.
 */ 
protected void processRequest(HttpServletRequest request, HttpServletResponse response)   
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
        RequestDispatcher rd = request.getRequestDispatcher("JSP/lagTilbakemelding.jsp");
        rd.include(request, response);
        
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:17,代碼來源:lagTilbakemelding.java

示例7: processRequest

import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    RequestDispatcher rd = request.getRequestDispatcher("JSP/RessurserM4.jsp");
        rd.include(request, response);    
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:16,代碼來源:RessurserM4.java

示例8: processRequest

import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    RequestDispatcher rd = request.getRequestDispatcher("JSP/RessurserM15.jsp");
        rd.include(request, response);    
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:16,代碼來源:RessurserM15.java

示例9: processRequest

import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    RequestDispatcher rd = request.getRequestDispatcher("JSP/RessurserM2.jsp");
        rd.include(request, response);    
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:16,代碼來源:RessurserM2.java

示例10: processRequest

import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    RequestDispatcher rd = request.getRequestDispatcher("JSP/RessurserM5.jsp");
        rd.include(request, response);    
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:16,代碼來源:RessurserM5.java

示例11: processRequest

import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    RequestDispatcher rd = request.getRequestDispatcher("JSP/RessurserM12.jsp");
        rd.include(request, response);    
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:16,代碼來源:RessurserM12.java

示例12: processRequest

import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    RequestDispatcher rd = request.getRequestDispatcher("JSP/RessurserM9.jsp");
        rd.include(request, response);    
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:16,代碼來源:RessurserM9.java

示例13: processRequest

import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    RequestDispatcher rd = request.getRequestDispatcher("JSP/RessurserM14.jsp");
        rd.include(request, response);    
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:16,代碼來源:RessurserM14.java

示例14: processRequest

import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    RequestDispatcher rd = request.getRequestDispatcher("JSP/RessurserM13.jsp");
        rd.include(request, response);    
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:16,代碼來源:RessurserM13.java

示例15: processRequest

import javax.servlet.RequestDispatcher; //導入方法依賴的package包/類
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    RequestDispatcher rd = request.getRequestDispatcher("JSP/Innstillinger.jsp");
        rd.include(request, response);    
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:16,代碼來源:Innstillinger.java


注:本文中的javax.servlet.RequestDispatcher.include方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。