views:

533

answers:

1

Is there a way to get which JSP is currently rendered, with JSTL or Struts (or without)? like _ _ file _ _ in Python and PHP?

+3  A: 

Well ... yes ... in a way

String __jspName = this.getClass().getSimpleName().replaceAll("_", ".");

I'm using a JSP called pre.jsp for that which I include at the top of each JSP in my webapp:

<%@page import="org.apache.log4j.Logger"%>
<%
    String __jspName = this.getClass().getSimpleName().replaceAll("_", ".");

    Logger log = Logger.getLogger(this.getClass().getName());
    log.info("BEGIN JSP "+__jspName);
%>
<!-- BEGIN <%=__jspName %> -->

Plus I put this at the end of each JSP:

<!-- END <%=__jspName %> --><% log.info("END JSP "+__jspName); %>

That gives me a consistend log. To make sure each JSP is "correct", I have a check in my build script which just looks for the two strings "/pre.jsp" and `END <%=__jspName.

Aaron Digulla
Yeah. that was exactly the usecase I had... I guess it'll do
elzapp