0

我在 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() + " -->");
                }
            %>
4

2 回答 2

0

我们可以使用下面的 SSI 代码来替换相关 JSP 代码片段中的初始部分吗?<!--#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 -->

于 2012-01-18T13:44:18.177 回答
0

是的,你可以做到。您只需要记住,如果index.inc不是普通的 HTML 文档,而是包含 JSP 标记和 scriptlet 等,它将无法工作。SSI 不会对其进行评估。

于 2012-01-17T11:45:30.833 回答