0

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.

Aman Agarwal
  • 727
  • 6
  • 15

1 Answers1

2

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.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • Actually I am planning to write a different jar for the application, is it possible to get css in elegant manner in that case. – Aman Agarwal Dec 08 '12 at 15:23
  • I don't understand what you're asking. Be more explicit. – JB Nizet Dec 08 '12 at 15:28
  • I want to create a jar for jsp tag widgt which will contain js and css. and I want to addd these js and css in my application in elegant manner. – Aman Agarwal Dec 08 '12 at 15:42
  • And my answer is: put the classes implementing these JSP tags in a jar, and in the same jar, under META-INF/resources, put the JS and CSS files used by the tags. The developers will just have to drop the jar file into their webapp to use your tags. The CSS and JS files will be served by the web container directly from the jar file. The error.css file in your example must be under META-INF/resources. Not directly under META-INF. – JB Nizet Dec 08 '12 at 17:04
  • Do you use it in a servlet 3.0 webapp? How is it not working? – JB Nizet Dec 09 '12 at 10:36