GeeCON Prague 2014*
The moose likes Servlets and the fly likes is there any method for finding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "is there any method for finding" Watch "is there any method for finding" New topic
Author

is there any method for finding

ramesh kothakonda
Ranch Hand

Joined: Feb 14, 2006
Posts: 40
hi javaranchers,
Is there any method for finding absolute path of Webapplication in servltes.
if our webapplication folder name is mywebapp .
It is available in webapps folder. May i know the absolute path of mywebapp folder.

if you give me answer i will be very thankfull in advance.
thanking you
regards
[ November 14, 2006: Message edited by: Bear Bibeault ]

The object oriented way of becoming "RICH" is by INHERITANCE<br />Whoever said money can't buy happiness, didn't know where to shop.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you're app has been deployed as an exploded file structure, ServletContext.getRealPath("/") will return the path.

If you're app was deployed as a packed war archive then, there really is no path and getRealPath will return null.

java.lang.String&#41;" target="_blank" rel="nofollow">http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String)
[ November 14, 2006: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
ramesh kothakonda
Ranch Hand

Joined: Feb 14, 2006
Posts: 40
thank you for giving response,
Actually my requirement is to upload a file in specific directory.
Suppose I am having directory structure like
webapps
application
WEB-INF
IMAGES
some static resources
I want to upload a file into images folder.
In what way i can get the real path of our webapplication .I am doing this one in struts.

Thanking you
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61305
    
  66

Please read Ben's response again. He has answered your question.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

Simple way to do this is,

1. Add your real path where you want to upload files to application.properties file.

2. Read URL from the property file from your JSP or Servlet.

In furture if you want to change URL, you just need to change in property file.

HTH,


Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />prabhu.venkatachalam@gmail.com
 
GeeCON Prague 2014
 
subject: is there any method for finding