Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet context

 
pradeep raju
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65110
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the Servlets FAQ entry on "What is the difference between the init() and init(ServletConfig) methods?"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic