Java – include the contents of the JSP in the servlet
•
Java
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/my@R_531_2419@.jsp // (also,with the full context of the servlet) ... out.println("</html>"); out.close(); } catch (IOException e) { e.printStackTrace(); } } }
Is there a problem with this (has the response been submitted?), What shall I do?
Solution
request.getRequestDispatcher("/WEB-INF/my.jsp").include(request,response);
request.getRequestDispatcher("/WEB-INF/my.jsp").include(request,response);
But you shouldn't output HTML servlets like this Just use JSP, which contains < jsp: Include / > or <% @ include file = ".."% >
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码