Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getRealPath() returning null

 
Anjali S Sharma
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ujjwal soni wrote: try giving the parameter including your context path.

No, the context path is never required.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PageContext is only available within JSP pages and is not a part of Servlets.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks bear
 
Anjali S Sharma
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic