Include the content of a jsp in a servlet(在 servlet 中包含 jsp 的内容)
问题描述
I have this servlet:
public class SaveImage extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = null;
try {
out = response.getWriter();
out.println("<html>");
...
// I want to include here the content of this jsp:
// /WEB-INF/mybox.jsp
// (also, with the full context of the servlet)
...
out.println("</html>");
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Is there a problem doing it (response already committed?), how can I do this?
request.getRequestDispatcher("/WEB-INF/my.jsp").include(request, response);
But you should not a servlet for outputting html like that. Just use a jsp, with either <jsp:include />
or <%@ include file=".." %>
这篇关于在 servlet 中包含 jsp 的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!