开发者

Getting a Web Accessible Directory in Spring-MVC/Java

开发者 https://www.devze.com 2022-12-27 07:58 出处:网络
Simple problem, I need to write a sitemap to my web root directory so that it is accessible as so: http://mysite.com/sitemap.xml

Simple problem, I need to write a sitemap to my web root directory so that it is accessible as so:

http://mysite.com/sitemap.xml

I want the code to look like:

File f = n开发者_运维技巧ew File( someMethodToGetWebRootDirectory() );

But I don't know what should be in that method


Will something along the lines of:

File classesDir = new File(YourServlet.class.getProtectionDomain()
    .getCodeSource().getLocation().getPath().replaceAll('/', File.separator));
File rootDir = classesDir.getParentFile().getParentFile();

work?

0

精彩评论

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