• Post Reply Bookmark Topic Watch Topic
  • New Topic

Resources on WebApps

 
Mario Rendon
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi i have a question i have a WebApp in wich i want to include some resources ( more than images and properties files) but i want such resources to be used by my Webapp's Classes . i have seen that my classes can reach local file system on server; but i want to reach the resources defined on my webapp..

Any suggestion?
 
Mario Rendon
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I respond to MySelf .. (hope i'm correct)
after thinking it along a lot i have noticed that Resources in a webapp are as resources in a web server .
you can't use those in a File Manner so you have to use as a Web Resource Manner ..
i enclose the code to access the file

URLConnection con;
URL myUrl= new URL("http://server/webapp/resource");
InputStream istream;

con = myUrl.openConnection();
con.connect();
encoding = con.getContentEncoding();
istream = con.getInputStream();
// after openning the input stream i can read
// as any file

that's my solution i don't know if it's the best solution any suggestions ??
or theres some other more efficient solutions ??
i know that i'm making a loopback to my own resource in the web server bu't the resource is managed by the J2EE server and it could be managed as an archive as a part of a war . since i don't know how is managed i can't assure where is it located.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Making a loopback to your own server is OK as a technique if you never plan to change the name of the application or the server, or to move your application to somewhere else.
What I do to access arbitrary web aplication resources is to put the files in WEB-INF/classes and use "getResourceAsStream". here's some example code from one of my projects:

Hope this helps.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!