当前位置: 首页>>代码示例>>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;未经允许,请勿转载。