- 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.
推薦閱讀
- OpenCV實例精解
- Python Geospatial Development(Second Edition)
- 新編Premiere Pro CC從入門到精通
- HTML5+CSS3網站設計教程
- QGIS By Example
- Hands-On Reinforcement Learning with Python
- Advanced Oracle PL/SQL Developer's Guide(Second Edition)
- Node.js 12實戰
- Arduino電子設計實戰指南:零基礎篇
- Visual Basic程序設計基礎
- Python編程快速上手2
- HTML5與CSS3權威指南
- C語言程序設計實驗指導教程
- Maya Programming with Python Cookbook
- Python編程基礎