Skip to content

Instantly share code, notes, and snippets.

@wendal
Created February 16, 2012 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wendal/1843735 to your computer and use it in GitHub Desktop.
Save wendal/1843735 to your computer and use it in GitHub Desktop.
获取项目根路径的简单方法
import java.io.File;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class XServletContextListener implements ServletContextListener {
public static String ROOT;
public void contextDestroyed(ServletContextEvent event) {
ROOT = event.getServletContext().getRealPath(File.separator);
}
public void contextInitialized(ServletContextEvent arg0) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment