• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating a new folder under WEB-INF

 
Johnny Brown
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65122
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not something you would do in a JSP, so moved to the Servlets forum.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65122
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65122
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What the problem with using getRalPath()?
 
Johnny Brown
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic