本文整理匯總了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));
}