- Jakarta EE Cookbook
- Elder Moraes
- 104字
- 2021-06-24 16:12:40
How to do it...
You need to perform the following steps to try this recipe:
- We will create a servlet:
@WebServlet(name = "ServerPush", urlPatterns = {"/ServerPush"})
public class ServerPush extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse
response) throws ServletException, IOException {
PushBuilder pb = request.newPushBuilder();
if (pb != null) {
pb.path("images/javaee-logo.png")
.addHeader("content-type", "image/png")
.push();
}
try (PrintWriter writer = response.getWriter();) {
StringBuilder html = new StringBuilder();
html.append("<html>");
html.append("<center>");
html.append("<img src='images/javaee-logo.png'><br>");
html.append("<h2>Image pushed by ServerPush</h2>");
html.append("</center>");
html.append("</html>");
writer.write(html.toString());
}
}
}
- To try it, run the project in a Jakarta EE 8 server and open this URL:
https://localhost:8181/ch01-servlet/ServerPush
Let's now see how this works.
推薦閱讀
- Vue.js設(shè)計(jì)與實(shí)現(xiàn)
- Drupal 8 Blueprints
- 微服務(wù)設(shè)計(jì)原理與架構(gòu)
- Apache Spark 2 for Beginners
- Mastering Predictive Analytics with Python
- 零基礎(chǔ)輕松學(xué)SQL Server 2016
- 移動(dòng)界面(Web/App)Photoshop UI設(shè)計(jì)十全大補(bǔ)
- Learning Probabilistic Graphical Models in R
- Fast Data Processing with Spark(Second Edition)
- R數(shù)據(jù)科學(xué)實(shí)戰(zhàn):工具詳解與案例分析
- Java圖像處理:基于OpenCV與JVM
- Learning Splunk Web Framework
- 現(xiàn)代CPU性能分析與優(yōu)化
- 零基礎(chǔ)學(xué)SQL(升級(jí)版)
- C Primer Plus(第6版)中文版【最新修訂版】