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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet context" Watch "servlet context" New topic
Author

servlet context

pradeep raju
Greenhorn

Joined: Feb 07, 2006
Posts: 7
hi
please see my code..
ServletConfig config=getServletConfig();

ServletContext ctxt=config.getServletContext();
System.out.println("path "+ctxt.getRealPath("/"));

iam getting null pointer exception..
i dont know the reason behind this can any one help
John Russell
Greenhorn

Joined: Feb 07, 2006
Posts: 17
Originally posted by pradeep raju:

ServletContext ctxt=config.getServletContext();
System.out.println("path "+ctxt.getRealPath("/"));

iam getting null pointer exception..
i dont know the reason behind this


Is your web application root directory part of the file system, or is it in a war file? The javadoc for ServletContext getRealPath mentions this:

This method returns null if the servlet container cannot translate the virtual path to a real path for any reason (such as when the content is being made available from a .war archive).
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61426
    
  67

See the Servlets FAQ entry on "What is the difference between the init() and init(ServletConfig) methods?"


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: servlet context