我们可以用服务器端包含替换 servlet 上下文对象并尝试缓存块吗?
我在 JSP 中有以下代码片段:我们可以用服务器端包含替换它吗? 具体来说,是对 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() + " -->");
}
%>
I have the below code snippet in JSP : Can we replace this with Server Side include ?
Specifically, the call to the Servlet Context object and the try - catch block.
Please advise :
Thanks in advance.
<%
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() + " -->");
}
%>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,你可以做到。您只需记住,如果
index.inc
不是普通的 HTML 文档,而是包含 JSP 标记和 scriptlet 等,则它将无法工作。 SSI 不会对它们进行评估。Yes, you can do it. You only need to keep in mind that it won't work if the
index.inc
is not a plain vanilla HTML document, but contains JSP tags and scriptlets and so on. They will not be evaluated by SSI.我们可以使用下面的 SSI 代码来替换相关 JSP 代码片段中的初始部分吗?
Can we use the below SSI code as the replacement for the initial part in the JSP code fragment in question ?
<!--#if expr="getServletConfig().getServletContext().getServletContextName().startsWith("internal")" -->
<!--#set var="includeURL" value="/ctx/hub_inside/support/index.inc" -->
<!--#else -->
<!--#set var="includeURL" value="/ctx//EMEA/main/Intranet/Inside/hub_inside/support/STAGING/index.inc" -->
<!--#endif -->