开发者

How to fetch actual web resource source file path in java?

开发者 https://www.devze.com 2023-02-09 14:56 出处:网络
I have developed java application whichis actually stored at d drive.I have imported that application into eclipse which is stored at C drive.

I have developed java application which is actually stored at d drive.I have imported that application into eclipse which is stored at C drive. In my application there is one folder named as 'Image'. So whenever I se开发者_开发知识库arch for the real Path of image folder through Servlet-context or request etc it gives me the path of C:\eclipse\spring-insight-instance\wtpwebapps\EAPortal\images

But i want to fetch the actual path of that image folder.Means path of images at D drive. How i should fetch it?

Thanks in Advance, Tushar Dodia


I don't believe there is a way to do this. Your web app container knows nothing about Eclipse and how it publishes web apps. In either case, you should not try to do this. Using getRealPath() method is most often the wrong way to approach a problem. In most cases, by the time the app is deployed in production, there is no real path as the app is contained by a .war file.

  1. If the images are static resources, you should be using ServletContext.getResourceAsStream method to read these images.

  2. If the images folder is a location where your app both reads and writes, then it should not be contained by your app. Separate it out from your application logic and then provide the location of the data directory to your app by using Java system property or an environment variable. Your specific web app container may have other options for passing parameters to a web app.

0

精彩评论

暂无评论...
验证码 换一张
取 消