Two Laptop Bag
The moose likes Servlets and the fly likes request.getSession().getServletContext().getRealPath( Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "request.getSession().getServletContext().getRealPath("/") with java.lang.NullPointerException" Watch "request.getSession().getServletContext().getRealPath("/") with java.lang.NullPointerException" New topic
Author

request.getSession().getServletContext().getRealPath("/") with java.lang.NullPointerException

Deepu Surendran
Greenhorn

Joined: Feb 07, 2013
Posts: 2
Dear all,

I am working on a java web project using struts2. My developing environment is Eclipse+ tomcat on windows

I encountered a problem when I would like to get the path of current project.

This is the code I am using to get the path.
String filePath = request.getSession().getServletContext().getRealPath("/");

But it always returns java.lang.NullPointerException

Hope any experts could give me some help.



Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56229
    
  13

Debugging 101: if you are getting an NPE, then something in the statement is returning null. Try each one to see which it is.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: request.getSession().getServletContext().getRealPath("/") with java.lang.NullPointerException
 
Similar Threads
request.getSession().getServletContext().getRealPath("/") with java.lang.NullPointerException
creating file relative to root of web application in windows OS
Accessing File from ActionClass
Uploading files to the current directory.
want to insert user-defined pass-phrase