以编程方式包含 JSP 页面
我需要在 Tag
类中包含一个 JSP 页面。我相信使用 API 将 JSP 页面包含在另一个 JSP 页面中的标准方法是这样的:
request.getRequestDispatcher("included.jsp").include(request, response);
但是,我注意到包含的页面呈现在生成页面的顶部,无论代码位于何处。无论代码是放置在 Tag
类中还是直接作为 scriptlet 放置在 JSP 文件中,都是如此。另一方面,
操作按预期工作,呈现标记出现在 JSP 文件中的包含页面。
如何在类中包含 JSP 页面,使其行为与
相同?无法在 Tag 类中调用
操作,是吗?
I need to include a JSP page in a Tag
class. I believe the standard way to include a JSP page within another JSP page using API is this:
request.getRequestDispatcher("included.jsp").include(request, response);
However, I noticed that the included page is rendered at the top of the generated page, no matter where the code is located. This is true whether the code is placed in a Tag
class or directly in the JSP file as scriptlet. On the other hand, the <jsp:include>
action works as expected, rendering the included page where the tag appears in the JSP file.
How do I include a JSP page in a class so that it behaves the same as the <jsp:include>
? There's no way to invoke the <jsp:include>
action within a Tag class, is there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许您的标记类应该在调用
request.getRequestDispatcher("included.jsp").include(request, response);
之前调用pageContext.getOut().flush();
>Perhaps your tag class should call
pageContext.getOut().flush();
prior to callingrequest.getRequestDispatcher("included.jsp").include(request, response);
我讨厌偷懒,但为什么不直接看一个 JSP 编译文件呢?例如,tomcat 将它们编译到 \work,您可以在那里查看它生成的 java。
I hate to be lazy, but why not just look at a JSP compiled file. for example, tomcat compiles these to \work, and you can VIEW the java it produced there.