为什么不能在HttpServletResponse中允许“<%@ include file”?

时间:2016-01-16 07:38:28

标签: java jsp servlets

好的,我收到了这个jsp文件&它运作正常

<html>
<head><title>Account</title></head>
<body>
<%@ include file="header.jsp" %>
</body>
</html>

现在,我有了一个servlet

 public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {
   resp.getWriter().println("<html>"+

                    "<head><title>Account</title></head>"+
                    "<body>"+

                    "<%@ include file=\"header.jsp\" %>"+

                    "</body"+
                    "</html>"
    }

servlet打印出<%@ include file="header.jsp" %>作为页面上的文字&amp;无法理解它是<%@ include file="header.jsp" %>

如何让servlet打印出与上面提到的jsp文件完全相同的结果?

1 个答案:

答案 0 :(得分:1)

request.getRequestDispatcher("/WEB-INF/header.jsp").include(request, response);

但你应该避免这种情况。