The power of JSTL's <c:import/> tag

    Since yesterday, I was having trouble with JSP's <jsp:include/> tag. I had to include a page which has a dynamic content in it. I was strict into following the model 2 approach so I wasn't even a little tempted to include scriptlets in my page. Using <jsp:include/> tag, it is possible to incorporate a JSP file to another JSP file like this...

<jsp:include page="/templates/myincludepage.jsp"/>

    However, we always want to separate our business logic with the presentation layer. So by all means, we create a Servlet (or a Struts Action class in my case) to handle that. Ooops! Problem! When I tried to include an Action servlet that forwards to another page, it doesn't include the page!It literally forwards to that which shouldn't be the case!

<jsp:include page="/actions/"/> //WON'T WORK!!!

    So I googled and searched a few forums about this topic. Voila! I bumped into my never-before used tag in the JSTL tag library which is the <c:import/> tag. So now I could do...

<c:import url="/actions/"/>

And now the page gets included without me putting the business logic in it... Sorted!

Published 06-21-2006 9:23 PM by lamia
Filed under: ,