*
The moose likes Servlets and the fly likes Creating a new folder under WEB-INF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Creating a new folder under WEB-INF" Watch "Creating a new folder under WEB-INF" New topic
Author

Creating a new folder under WEB-INF

Johnny Brown
Greenhorn

Joined: Jul 27, 2009
Posts: 10
Hello gurus,
This is in continuation on my earlier post http://www.coderanch.com/t/455889/Websphere/Image-location-Websphere

Someone said that if I create the new folder (that will get image files when the Action class runs) under WEB-INF, it can be referenced easily in the JSP.
Now, I am not sure about creating folder under WEB-INF. Is there any easy way to create a folder and files under WEB-INF dynamically?

I am completely lost on this issue.

Get me some idea, your next be on me. :-)

Thanks.
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Your Java Classes are free to access, modify, manipulate data in the WEB-INF folder, clients however, do neither have access to these resources nor can they modify them.

So, whenever you have e.g. a picture under your WEB-INF folder, the only way to go when you want to serve it back to the client is writing a servlet that obtains it.
It is a common practice for access control. A website that offers downloads for registered users only would use this approach to restrict their resources.


JDBCSupport - An easy to use, light-weight JDBC framework -
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

Not something you would do in a JSP, so moved to the Servlets forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

If you don't need to restrict access, WEB-INF is a poor place to put them. Unless you are running out of an unexpanded war file (in which case this conversation is moot), you can find the file system location of the web app with ServletContext.getRealPath() and use noremal Java File I/O from there.
Johnny Brown
Greenhorn

Joined: Jul 27, 2009
Posts: 10
Wow..
I love beer. Literally.
Just check the number responses (and notice the type of responses too ) on my two threads.
Thank you fellas.

Fun apart,
Little more info about my requirement:
Action class creates charts using JFree chart and JSP access those chart images.

Following is the current setup.
At Java class:

... and at the JSP:

This setup works fine with Tomcat as webapps/<applicationName>/charts is accessible there. When we move this to WebSphere, not sure what needs to be changed.


you can find the file system location of the web app with ServletContext.getRealPath()

Action class calls another standard java class that creates images. I am clueless how to use ServletContext.getRealPath there.
Update: I retrieve following paths by using File(System.getProperty(dir)).getCanonicalPath();
Tomcat: C:\Program Files\apache-tomcat-6.0.18\bin
WebSphere: C:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\profiles\default
Johnny Brown
Greenhorn

Joined: Jul 27, 2009
Posts: 10
Bear Bibeault:
Please do not cross-post the same question in multiple forums.

Sure, Sheriff. I thought, since this second part of my question related to Servlets, I should post it here. I feel stupid for not knowing the rules.
I'll be careful. Thanks for locking that thread for me. I was thinking of leaving a note there.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

What the problem with using getRalPath()?
Johnny Brown
Greenhorn

Joined: Jul 27, 2009
Posts: 10
Thank you, friends.
I got it resolved using getRealPath().

Thanks for the tip, Sheriff. Used it and resolved the issue.
Bear Bibeault wrote:What the problem with using getRalPath()?

To be honest with you, laziness was the problem. Had to think the way to use it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating a new folder under WEB-INF
 
Similar Threads
Adding a Plugin - Jsp in pages folder
HTTP Status 404 - /Beer-v1/form.html
Jsp under WEB-INF
Basic Tomcat question
Jforum install problems on godaddy