本文整理汇总了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));
}
示例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);
}
}
示例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());
}
}
示例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));
}