I have seen answers how to write jpg as response. I would like to write both html
and jpg
.
What I have now:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<h1 style='text-align:center;'> Welcome to our BookStore </h1>");
out.println("<p style='text-align:center;'><img src='book_store_image.jpg' alt='books img' style='width:304px;height:228px;'></p>");
out.println("<form style='text-align:center;'>" +
"<a href='" + request.getContextPath() + "/books'>Buy books</a><br/><br/>" +
"<a href="+ request.getContextPath() + "/sellerPage'>Sell books</a>" +
"</form>");
}
I know I cannot fetch image by doing <img src='book_store_image.jpg'
Question:
Should I open several output streams for it: one for setContentType("text/html");
and one for img
?