如何使用 include 指令根据请求属性包含文件
题
我想根据请求属性值包含一个文件。
${theme} -> themeA
总结。我想要这样的东西:
<%@ include file="../themes/${theme}/jsp/content/welcome.jsp"%>
有什么简单的解决方法吗?
解决方案
不适用于 <%@ include%>,因为那是静态/编译时包含。您可以改为使用 <jsp:include> 标记,该标记在运行时评估,并包含 结果 执行该页面,而不是在编译时包含页面本身。
要比较 include 指令和 <jsp:include> 之间的所有差异,请查看 JSP2.0参考
<jsp:include page="../themes/${theme}/jsp/content/welcome.jsp">
如果您使用 JSTL,<c:import> 标记也可以工作。
其他提示
<c:import url="../themes/${theme}/jsp/content/welcome.jsp"/>
不隶属于 StackOverflow