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() + " -->");
}
%>
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.