如何使用 include 指令根据请求属性包含文件
我想根据请求属性值包含一个文件。
${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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不与 <%@ include%> 一起使用 因为这是静态/编译时包含。标签,在运行时评估,并包含执行该页面的结果,而不是在编译时包含页面本身。
您可以改为使用
比较 include 指令和之间的所有差异 查看 JSP2.0 参考 <
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
The <c:import> tag would also work if you are using JSTL.