File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Conditionally load a java script file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Conditionally load a java script file" Watch "Conditionally load a java script file" New topic

Conditionally load a java script file

PradeepPillai Pradeep
Ranch Hand

Joined: Nov 15, 2005
Posts: 186
We have a javascript file called "sitestat.js". We have it included in many jsp files that are reusable and we construct other main jsp files using these reusable jsps. The problem is that as a result of including these reusable jsps in other jsps, we ended up including "sitestat.js" multiple times in a jsp. Is there any way to load a jsp file conditionally only if it is not loaded already?
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63858

Sounds like you need better organization for your JSP files. But as I doubt you;'d take that advice, you can set a scoped variable in the request when you include the script file and check it later to see of you need to include the file again. The <c:set> and <c:if> JSTL tags can be used for this. In fact, you can even write a custom tag to handle all of that for you in one place.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Conditionally load a java script file
jQuery in Action, 3rd edition