将 JSP 文件包含在 Java 中
我知道在 jsp 中包含外部文件可以通过以下方式完成:
<%@ include file="banner.jsp" %>
但是有没有办法在 java 类/对象中执行此操作?
I know that including and external file in jsp can be done with something like this:
<%@ include file="banner.jsp" %>
But is there a way of doing this inside a java class/object?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过
RequestDispatcher
:请注意,您应该很少需要这样做。这意味着您正在从 servlet 输出视图内容,并且您应该主要在 jsp 中执行此操作。
You can do it inside a servlet (or any class having access to the current request), via the
RequestDispatcher
:Note that you should rarely need to do this. It would mean that you are outputting view content from a servlet, and you should do that mainly in a jsp.
在Servlet中你可以调用:
In Servlet you can call:
没有办法做到:
在java中,因为 - 正如您可以阅读的 这里是一个静态jsp include,它是在JSP编译时完成的,
我希望java中有静态代码这样的东西。
There is NO way to do:
in java, because - as you can read here that is a static jsp include, which is done at JSP compile time,
I wish there was such a thing as static code includes in java.