Question

I am using MVC model in which I am writing too many web based widgets for the different different application, which cause lot of repetitive work for me to resolve the problem I am planning to write the new package for the jsp tags for each widgets(using tld) and the generated jar I will include in lots of application which use those widgets and I am successfully able to that also.

But here I am bit concerned about the css and javascript, which is used by the widget.

let say I write css in jsp tag itself in library then in that case, it fetch css and script every time which incurs extra latency, in case if I write common css at client side then for the multiple applications which use my widget package need to write css again and again ?

The jar for widget which I included in my MVC project.

jar -tvf AcmeUIUtils-1.0.jar
     0 Fri Dec 07 07:41:56 IST 2012 META-INF/
   106 Fri Dec 07 07:41:54 IST 2012 META-INF/MANIFEST.MF
     0 Fri Dec 07 15:54:40 IST 2012 com/
     0 Fri Dec 07 15:54:40 IST 2012 com/amazon/
     0 Fri Dec 07 15:54:40 IST 2012 com/amazon/spotui/
     0 Fri Dec 07 15:54:40 IST 2012 com/amazon/spotui/basicui/
  2339 Fri Dec 07 02:11:38 IST 2012 com/amazon/spotui/basicui/AcmeMessage.class
  1684 Fri Dec 07 15:54:40 IST 2012 com/amazon/spotui/basicui/Ping.class
     0 Fri Dec 07 15:54:40 IST 2012 com/amazon/spotui/utils/
  2989 Fri Dec 07 15:54:40 IST 2012 com/amazon/spotui/utils/AcmeTags.class
     0 Fri Dec 07 07:41:40 IST 2012 META-INF/css/
   635 Fri Dec 07 07:40:14 IST 2012 META-INF/css/error.css
  1059 Fri Dec 07 14:47:20 IST 2012 META-INF/spot-ui-component.tld
     0 Fri Dec 07 15:54:40 IST 2012 test-resources/

Now my question is that how to load error.css in my application in elegant way ? or do I need to made changes at the widget level ?

I don't mind any opensource solution for the problem. But I need jsp tags only.

Was it helpful?

Solution

Since servlet 3.0, a jar file placed under WEB-INF/lib can contain resources that will be served directly by the webapp. These resources must be placed under the META-INF/resources directory of the jar file.

So if your tag library jar contains a file META-INF/resources/js/MyTaglib.js, this file will be directly available using the URL

http://the.host.com/theWebApp/js/MyTaglib.js

If you're targetting pre-servlet3.0 webapps, then tell the developers to deploy the CSS and JS files of your taglib under a specific directory in the webapp.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top