Jsp 我们可以替换servlet上下文对象并尝试使用服务器端包含的cach块吗?

Jsp 我们可以替换servlet上下文对象并尝试使用服务器端包含的cach块吗?,jsp,ssi,Jsp,Ssi,我在JSP中有以下代码片段:我们可以用服务器端包含替换它吗? 特别是对Servlet上下文对象和try-catch块的调用 请告知: 提前谢谢 <% String includeURL = ""; if (getServletConfig().getServletContext().getServletContextName().startsWith("internal")) { inc

我在JSP中有以下代码片段:我们可以用服务器端包含替换它吗? 特别是对Servlet上下文对象和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() + " -->");
                }
            %>

是的,你能做到。您只需要记住,如果
index.inc
不是一个普通的HTML文档,而是包含JSP标记和脚本等等,那么它将无法工作。SSI不会对它们进行评估。

我们可以使用下面的SSI代码替换所讨论的JSP代码片段中的初始部分吗?


你好,巴鲁,谢谢你的回复。什么可以替换servletContext对象和try-catch块。嗯,你到底在问什么?当我们编写SSI时,我们将如何替换下面的代码:getServletConfig().getServletContext().getServletContextName().startsWith(“内部”)