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


Java HttpServletRequest.newPushBuilder方法代碼示例

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


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

示例1: greeting

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * Method to receive a GET request for a Greeting.
 * @param request the HTTP request.
 * @param name the string containing the name
 * @return a Greeting
 */
@RequestMapping("/greeting")
public Greeting greeting(ServletRequest request,
    @RequestParam(value = "name", defaultValue = "World") String name) {

  HttpServletRequest httpServletRequest = (HttpServletRequest) request;
  if (httpServletRequest != null) {
    LOG.info("can cast to HttpServletRequest");
    if (null != httpServletRequest.newPushBuilder()) {
      PushBuilder pushBuilder = httpServletRequest.newPushBuilder();
      pushBuilder.path("/push-greeting?name=push");
      pushBuilder.push();
      LOG.info("##### has pushbuilder");
    } else {
      LOG.info("##### has no pushbuilder");
    }
  }

  jettyServerPushFunction.jettyServerPush(request);

  return new Greeting(counter.incrementAndGet(),
      String.format(template, name));
}
 
開發者ID:janweinschenker,項目名稱:servlet4-demo,代碼行數:29,代碼來源:GreetingController.java

示例2: doGet

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) {

        PushBuilder pushBuilder = req.newPushBuilder();
        if (pushBuilder != null) {
            pushBuilder
                    .path("resources/images/dukewaving.gif")
                    .addHeader("content-type", "image/gif")
                    .push();
            // Push more than one resource
//            pushBuilder
//                    .path("resources/images/dukewaving.gif")
//                    .addHeader("content-type", "image/gif")
//                    .push();
        }
        try (PrintWriter respWriter = resp.getWriter();) {
            respWriter.write("<html>"
                    + "<img src='resources/images/dukewaving.gif'>"
                    + "</html>");
        } catch (IOException ex) {
            System.out.println(ex);
        }
    }
 
開發者ID:javaee-samples,項目名稱:javaee8-applications,代碼行數:24,代碼來源:DukeServlet.java

示例3: doGet

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {

  resp.setContentType("text/html;charset=UTF-8");
  PushBuilder pushBuilder = req.newPushBuilder();
  if (pushBuilder != null) {
    pushBuilder
        .path("images/cat.png")
        .addHeader("content-type", "image/jpeg")
        .push();
    pushBuilder
        .path("http2-json")
        .addHeader("content-type", "application/json")
        .push();
  }
  try (PrintWriter respWriter = resp.getWriter()) {
    respWriter.write(new StringBuilder()
                         .append("<html>")
                         .append("<img src='images/cat.jpg'>")
                         .append("<p>Image by <a href=\"https://flic.kr/p/HPf9R1\">")
                         .append("Andy Miccone</a></p>")
                         .append("<p>License: <a href=\"https://creativecommons.org/")
                         .append("publicdomain/zero/1.0/\">")
                         .append("CC0 1.0 Universal (CC0 1.0) \n")
                         .append("Public Domain Dedication</a></p>")
                         .append("</html>")
                         .toString());
  }
}
 
開發者ID:janweinschenker,項目名稱:servlet4-demo,代碼行數:31,代碼來源:Http2Servlet.java

示例4: greeting

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * Method to receive a GET request for a Greeting.
 * @param request the HTTP request.
 * @param name the string containing the name
 * @return a Greeting
 */
@RequestMapping("/greeting")
public Greeting greeting(
    HttpServletRequest request,
    @RequestParam(value = "name", defaultValue = "World") String name) {

  PushBuilder pushBuilder = request.newPushBuilder();
  pushBuilder.path("/push-greeting?name=push");
  pushBuilder.push();

  return new Greeting(counter.incrementAndGet(),
      String.format(TEMPLATE, name));
}
 
開發者ID:janweinschenker,項目名稱:servlet4-demo,代碼行數:19,代碼來源:GreetingController.java


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