我有这个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(); } } }
这样做有问题吗(响应已经提交?),我该怎么做?
request.getRequestDispatcher("/WEB-INF/my.jsp").include(request, response);
但是您不应该使用servlet来输出html。只需使用jsp,<jsp:include />或者<%@ include file=".." %>
<jsp:include />
<%@ include file=".." %>