473,386 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How do you access application root static pages or WEB-INF jars in a non-servlet clas

In a general servlet class after deployment, you can access the application root as servletContext.getRealPath("/") to access any of the properties files in the "WEB-INF" directory or anywhere else in the /webapp-root/ directory.

How can we get the equivalent servletContext.getRealPath("/") in a non-servlet where you are interested to access a property file located in "/webapp-root/WEB-INF" or probably a text file stored in a static folder pages in the /webapp-root/pages/ folder.
Feb 19 '08 #1
2 2427
chaarmann
785 Expert 512MB
In a general servlet class after deployment, you can access the application root as servletContext.getRealPath("/") to access any of the properties files in the "WEB-INF" directory or anywhere else in the /webapp-root/ directory.

How can we get the equivalent servletContext.getRealPath("/") in a non-servlet where you are interested to access a property file located in "/webapp-root/WEB-INF" or probably a text file stored in a static folder pages in the /webapp-root/pages/ folder.
1.) dynamic read
get the windows environment variable for the webserver directory (e.g tomcat) and add ""/webapp-root/WEB-INF" to it. (or parse the tomcat configuration file where you have mapped the web-directory to a real path on your harddisk )

2.) hardcode read
- or you can just make a configuration file, which will be read from your non-servlet program, and put the whole path there inside,
- or you can pass the folder as a parameter to java when you start your non-servlet program
- or you can set thepath inside a (windows) environment variable and read it from there.

3.) database read
store the path inside a database table when you run the servlet. Then read this path when you run your non-servlet app.

4.) remote read:
use RMI, Corba or other ways (Sockets, pipes, shared memory) to pass the
path from one program to another.
Feb 19 '08 #2
I ended up hard coding.. I hate this.

Wish someone could teach me how to use context listener to initialize the variable as string from a servlet's servletContext() method and save to application scope and then be able to access this?

Or pass servletContext object itself to the non-servlet.

Help requested.
Feb 21 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ardin | last post by:
I know via mod rewrite you can mimi static pages, but how does one do this for ASP? Before I go crazy modifying my code to generate a static page for all of our products (1000's of html pages)...
0
by: ad | last post by:
I have used Data Application Access Block2 in my web application. Now I download the Library Data Access Application Block. and read the document. May be I am stupid, I can't migrate it to...
8
by: joe | last post by:
Some time ago I set up an ASP application that used a login page which checked a username and password against a database to determine a users authorization to access certain pages on the site....
5
by: Leszek | last post by:
Hello, Could anybody explain what's a difference between a virtual directory and an application root under IIS? I'm a little bit confused. This is mu problem: Let's assume the following...
1
by: Alan | last post by:
Here is an error message I received when tried to create new web project with C# for .NET The Web was created successfully, but an error occured when trying to contfigure the application root for...
3
by: Sheila Jones | last post by:
Hello, Could somebody explain (or point me to a website that does) the difference between a 'virtual directory' and an 'application root'? I don't really get it at the moment. Thanks.
6
by: Grant | last post by:
Hi, I'm trying to setup a web server to host asp.net 1.1... but keep getting the following error message: Hopefully someone can give me some ideas on what I may need to do. Thanks in...
2
by: Alphonse Giambrone | last post by:
I just downloaded the new MS Paterns & Practices Enterprise Library to use the Data Access Application Block in a web app. Am I missing something, or can the connection string only be set in the...
5
by: pittendrigh | last post by:
There must be millions of dynamically generated html pages out there now, built by on-the-fly php code (and jsp, perl cgi, asp, etc). Programatic page generation is transparently useful. But...
1
by: daonho | last post by:
Hi Everyone, I have encountered this problem that I am not able to figure out. Please drop me some lines if you have any idea how to solve this issue. I have a global.asax file in my web site. It...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.