File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes getRealPath() returning null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "getRealPath() returning null" Watch "getRealPath() returning null" New topic
Author

getRealPath() returning null

Anjali S Sharma
Ranch Hand

Joined: Jun 29, 2005
Posts: 279
I have Tomcat installed in Windows XP. In my web application deployed in tomcat, I have the following code line in my action class

String strFilePath = getPageContext().getServletContext().getRealPath(File.separator);

this gives me the value

C:\cvs_repo\Documentum\webtop\src\

Now this same application I have deployed on Weblogic (hosted on windows 2003 server). On this server, the above code line returns null

Now this same application is deployed on Weblogic (hosted on AIX box). On this machine this code line returns the correct file path.

Can somone please let me know why it is returning null on windows 2003 Weblogic.

Thank you
ujjwal soni
Ranch Hand

Joined: Mar 28, 2007
Posts: 403
Hi,

While giving the parameter for getRealPath().. try giving the parameter including your context path.

For eg: if your context path is /TestContext

try using



Basically getRealPath is not defined for applications deployed in a WAR file, and indeed works differently between different application servers (Tomcat and WebLogic for example).
In WebLogic, getRealPath returns null for WAR files.

See this discussion for ways around this limitation: http://www.experts-exchange.com/Web/Application_Servers/Weblogic/Q_21004006.html


Cheers!!!
Ujjwal B Soni <baroda, gujarat, india> <+919909981973>
"Helping hands are better than praying lips......"
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

ujjwal soni wrote: try giving the parameter including your context path.

No, the context path is never required.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Anjali S Sharma wrote:
String strFilePath = getPageContext().getServletContext().getRealPath(File.separator);


[sorry if i dont know]from where you get the method (getPageContext()) ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

PageContext is only available within JSP pages and is not a part of Servlets.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

thanks bear
Anjali S Sharma
Ranch Hand

Joined: Jun 29, 2005
Posts: 279
Bear Bibeault wrote:PageContext is only available within JSP pages and is not a part of Servlets.


getPageContext() is provided by the framework (Documentum) that we are using.




so, getPageContext() returns a valid object.
getPageContext().getServletContext() returns a valid object. Only getPageContext().getServletContext().getRealPath(File.separator) returns null in some of the conditions (as mentioned in the initial post)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

Anjali S Sharma wrote:
Bear Bibeault wrote:PageContext is only available within JSP pages and is not a part of Servlets.


getPageContext() is provided by the framework (Documentum) that we are using.

Don't you think that was relevant information to provide from the start? How are we to know what proprietary system provide or not (especially when they foolishly name things in conflict with standard elements)?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getRealPath() returning null