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

发布于 2024-12-27 12:39:38 字数 741 浏览 3 评论 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() + " -->");
                }
            %>

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

背叛残局 2025-01-03 12:39:38

是的,你可以做到。您只需记住,如果 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.

同尘 2025-01-03 12:39:38

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文