aspose file tools*
The moose likes Servlets and the fly likes get the environment var in the servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "get the environment var in the servlet" Watch "get the environment var in the servlet" New topic
Author

get the environment var in the servlet

zb cong
Ranch Hand

Joined: Jan 14, 2002
Posts: 416
hello
in my servlet,there is following code block:
File f=new File("%JAVA_HOME%\\test.txt");
f.createNewFile();
the "JAVA_HOME" is the environment variable of my windows.after i deploy it to jboss,it threw exception.that tell me can't find the path.
then i modify it as:
File f=new File("%JBOSS_HOME%\\test.txt");
f.createNewFile();
the "JBOSS_HOME" is definde in its "run.bat " file.
the code still don't work.
who can tell me :
1 how can i use the environment variable of os or app server?
2 how and where can i set up a envrionment variable as the base dir ?
thank you.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

There's no supported way to get the value of environment variables in Java. You'd be better off setting up a context-level init param in your web.xml for these types of config variables.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
zb cong
Ranch Hand

Joined: Jan 14, 2002
Posts: 416
thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: get the environment var in the servlet
 
Similar Threads
FileOutputStream and identifier \u0063
not able to get ContextPath(); getting null pointer exception
How t ofind JBOSS_HOME
Creating file on server - java.io.FilePermission - access denied
Tomcat in Eclipse File Write Permissions