如何使用 include 指令根据请求属性包含文件

发布于 2024-07-15 11:51:00 字数 214 浏览 6 评论 0原文

我想根据请求属性值包含一个文件。

${theme} -> themeA

总结。 我想要这样的东西:

<%@ include file="../themes/${theme}/jsp/content/welcome.jsp"%>

有什么简单的解决方法吗?

I would like to include a file depending on a request attribute value.

${theme} -> themeA

To sum up. I would like something like this:

<%@ include file="../themes/${theme}/jsp/content/welcome.jsp"%>

Any easy workaround?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

东走西顾 2024-07-22 11:51:00

不与 <%@ include%> 一起使用 因为这是静态/编译时包含。
您可以改为使用标签,在运行时评估,并包含执行该页面的结果,而不是在编译时包含页面本身。

比较 include 指令和之间的所有差异 查看 JSP2.0 参考 <

<jsp:include page="../themes/${theme}/jsp/content/welcome.jsp"> 

c:import> ; 如果您使用 JSTL,标签也可以工作。

Not with <%@ include%> as that is a static/compile time include.
You could instead use <jsp:include> tag, which is evaluated at runtime, and includes the result of executing that page, rather than including the page itself at compile time.

To compare all the differences between the include directive and <jsp:include> check out JSP2.0 Reference

<jsp:include page="../themes/${theme}/jsp/content/welcome.jsp"> 

The <c:import> tag would also work if you are using JSTL.

栖竹 2024-07-22 11:51:00
<c:import url="../themes/${theme}/jsp/content/welcome.jsp"/>
<c:import url="../themes/${theme}/jsp/content/welcome.jsp"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文