- 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.
推薦閱讀
- C及C++程序設(shè)計(第4版)
- SQL Server 從入門到項目實踐(超值版)
- HTML5+CSS3王者歸來
- JSP網(wǎng)絡(luò)編程(學(xué)習(xí)筆記)
- Learning Chef
- Building a Game with Unity and Blender
- Hands-On Image Processing with Python
- 深入淺出WPF
- MATLAB實用教程
- MySQL數(shù)據(jù)庫管理與開發(fā)實踐教程 (清華電腦學(xué)堂)
- Java系統(tǒng)化項目開發(fā)教程
- ExtJS高級程序設(shè)計
- 智能搜索和推薦系統(tǒng):原理、算法與應(yīng)用
- OpenCV 3計算機(jī)視覺:Python語言實現(xiàn)(原書第2版)
- Visual Basic語言程序設(shè)計基礎(chǔ)(第3版)