【发布时间】:2012-01-17 07:11:10
【问题描述】:
我在 JSP 中有以下代码 sn-p:我们可以用服务器端包含替换它吗? 具体来说,就是调用 Servlet Context 对象和 try-catch 块。
请指教:
提前致谢。
<%
String includeURL = "";
if (getServletConfig().getServletContext().getServletContextName().startsWith("internal")) {
includeURL = "/test/index.inc";
} else {
includeURL = "/testone/index.inc";
}
try {
%><jsp:include page="<%= includeURL %>" flush="true" /><%
} catch (Throwable e) {
out.println("<!-- Could not include file - ERROR: " + e.toString() + " -->");
}
%>
【问题讨论】: