【问题标题】:Can we replace servlet context object and try cach block with Server Side includes?我们可以用服务器端包含替换 servlet 上下文对象并尝试 catch 块吗?
【发布时间】: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() + " -->");
                }
            %>

【问题讨论】:

    标签: jsp ssi


    【解决方案1】:

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

    【讨论】:

    • 嗨,巴鲁,感谢您的回复。什么可以替代 servletContext 对象和 try - catch 块。
    • 呃,你到底在问什么?
    • 写SSI的时候,我们如何替换下面的代码:getServletConfig().getServletContext().getServletContextName().startsWith("internal")
    【解决方案2】:

    我们可以使用下面的 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 -->

    【讨论】:

      猜你喜欢
      • 2013-08-05
      • 2012-03-15
      • 1970-01-01
      • 2013-09-04
      • 1970-01-01
      • 1970-01-01
      • 2021-11-19
      • 2013-06-16
      • 2019-04-06
      相关资源
      最近更新 更多