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):
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
尝试“资源”JAR - 请参阅: http : //alexismp.wordpress.com/2010/04/28/web-inflib-jarmeta-infresources/
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.