Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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


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: 61299
    
  66

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]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: servlet context