简体   繁体   中英

Where to store images, CSS and javascript files on glassfish?

I've looked around a lot (trust me :) before posting this questions and I'm still confused. Here's the scenario:

Hosting a J2EE web-app on glassfish v3 using Restlet 2.0 The freemarker template files are located in the /WEB-INF folder. The templates link to jQuery/javascript files, some static images and stylesheets using relative URLs.

Since it's not a good practice to store them in /WEB-INF (as stated at many places on the web) I moved the files to the WebContent folder


WebContent:
+--Images
   -.jpg, .gif files
+--Styles
   -myStyle.css
+--Scripts
   +--jQLabel
   +--mColorPicker
      +--Images
      +--javascripts
         -.js files

I refer to them in the freemarker template/html as:

<link rel="stylesheet" type="text/css" href="${baseRef}/Styles/myStyle.css"  />

where ${baseRef} is the Root Reference of the site. The site is deployed at /Winbook. So the URL on the localhost for the css looks like this:

http://localhost:8080/Winbook/Styles/winbookwall.css <-- retrieved using a GET

Problem(s):

For each of the above resources I get a 404 :( I'm not sure if this is really how one should store css, images or scripts and whether the WebContent folder is a good place for it be stored.

Question(s):

  1. Why is the above not working? I mean there has to be a mistake and I just don't know about it :)
  2. What is the best place to store the above files on the web server/glassfish?
  3. How do I refer to those resources (in the HTML/freemarker template) if they are deployed in the .war? (They will get deployed in the war file if they are placed in WebContent, right? Is this 'legal' or good practice? Seems to smell :)
  4. Do we have to create alternate doc roots in glassfish for all such resources (or the equivalent Directory class in Restlet?)
  5. What is the 'best' way/place of/for such a deployment for an intranet based application to seamlessly locate the resources? JNDI based lookup? (I don't know how that would work, another question probably on SO ;)

I am totally confused! It's been a while since I had to write a full end to end web app and this was usually taken care of by the 'others' :)

Thanks!

I'm probably late on posting an answer to this but here it is. As I mentioned it Restlet intercepts the URLs and you HAVE to use the Directory class to return static content - initialized with the path "war:///" or "war:///images/" etc., for each of the folders.

The reason it wasn't working was with the Routing issues of Restlet - The directory folder was 'last' in the code order of URLs. Directories are created with Template.MODE_STARTS_WITH and the others (ie, Restlets or other resources) are Template.MODE_EQUALS

You should either change the order of routing manually or push it at the top of the list of URIs when routing.

Hope that helps anyone stumbling on the same problem.

Here is the related question that Jerome answered: Restlet Routing Nightmare

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM