Reputation: 63586
I am trying to do some debugging of JSP files that include multiple levels of nested includes.
e.g.
foo.jsp
<%@ include file="bar.jsp"%>
bar.jsp
<%@ include file="baz.jsp"%>
baz.jsp
<%@ include file="boz.jsp"%>
To help determine where a certain file is actually included I placed a simple line to output a javascript alert in various files so that I can catch it when a page is rendered.
e.g. (formatted over multiple rows for readability)
<script type="text/javascript">
alert('Accessing File: <%=this.getName()%>' +
'\n\nCompiled as: <%=pageContext.getPage().getClass().getName()%>' +
'\n\nRequested by: <%=request.getRequestURI()%>');
</script>
Thus ideally what I want to see if I inject this into baz.jsp
is:
Accessing File: baz.jsp
Compiled as: _foo__jsp.java
Requested by: foo.jsp
However since the <%@include%>
JSP directive is static - the content is included at translation time, thus everything becomes "foo".
I'd really, really like to not have to edit/hardcode a filename into each debug line I add.
Does anyone have a clever solution to obtain the "true" source filename of a JSP... if it is @included in another file?
Upvotes: 3
Views: 2296
Reputation: 597164
<jsp:include>
translates to RequestDispatcher.include(..)
and is evaluated at request time, rather than statically. So try using it.
Upvotes: 2