1

I am a bit fresh to JSP and I am having problems understanding what could be wrong with the following include code within my JSP:

../test-project/main.jsp

<jsp:include page="../blueprint-project/header-includes.jsp"/>
<!-- More HTML/CSS code below which is working and not blocking -->

../blueprint-project/header-include.jsp

<%@ taglib uri="struts-sslext" prefix="sslext" %>
<%@ page import="mts.psp.web.struts.util.WebSessionUtil" %>
<%@ page import="mts.psp.web.struts.util.ActionUtil" %>
<%@ page import="mts.psp.metrics.entity.TestGroup" %>
<%@ page import="mts.psp.util.common.ConfigUtil" %>
<%@ taglib uri="struts-tiles" prefix="tiles" %>
<%@ taglib uri="struts-html" prefix="html" %>
<%@ taglib uri="struts-logic" prefix="logic" %>
<%@ taglib uri="struts-bean" prefix="bean" %>
<%@ taglib uri="jstl-core" prefix="c" %>

The code in header-include.jsp previously existed within main.jsp at the top of the page. What I am trying to do is take this code, put it in another .jsp file (named header-include.jsp) and have it dynamically included into main.jsp

When I attempt to do this, I get a 500 error. Is what I am attempting to do possible/correct at all? Any help from the community would be outstanding.

AGE
  • 3,752
  • 3
  • 38
  • 60
  • 1
    No, it can't be done with a **dynamic** include, which is resolved at runtime. How could the JSP compiler understand that you use those taglibs if they are included dynamically, at runtime? – JB Nizet Feb 23 '15 at 18:25
  • That's very helpful, is there any way in which this can be accomplished that you know of, or is perhaps my thinking around this just way off and it's best to leave the code as it was originally? – AGE Feb 23 '15 at 18:34
  • 2
    Use a **static** include. http://stackoverflow.com/questions/14580120/whats-the-difference-between-including-files-with-jsp-include-directive-jsp-in. That said, I've had bad experiences with IDEs doing that, because it couldn't understand the JSP tags, provide auto-completion, etc. – JB Nizet Feb 23 '15 at 18:36
  • @JBNizet your suggestion lead me to the right approach, using a static include was the correct way of going about it. – AGE Mar 11 '15 at 18:00

1 Answers1

1

It seems all I had to do was to use a static include, as suggested in the comments:

<%@ include file="../blueprint-project/header-includes.jsp" %>

Static include allowed me to add the content of header-includes.jsp at translation time into the current page. This is clearly evidenced in the oracle docs as well as this stack overflow answer.

Community
  • 1
  • 1
AGE
  • 3,752
  • 3
  • 38
  • 60