java web项目获取项目路径
2020-12-13 04:12
标签:stat loader object tco nav load omr 文件路径 return 1.方法一 调试时只能获取eclipse 项目未编译前的路径 不太好用 2.方法 二 获取项目运行时的真实类路径 java web项目获取项目路径 标签:stat loader object tco nav load omr 文件路径 return 原文地址:https://www.cnblogs.com/jiangfeilong/p/11106129.html /* private static Logger logger = Logger.getLogger(BookController.class); */
@RequestMapping("/index")
public String bookHandle(HttpServletRequest servlet) {
JSONObject json = JsonResourceUtils.getJsonObjFromResource
("static/json/book_nav.json",servlet.getServletContext().getRealPath("/"));
return "book";
}
/* private static Logger logger = Logger.getLogger(BookController.class); */
@RequestMapping("/index")
public String bookHandle(HttpServletRequest servlet) {
JSONObject json = JsonResourceUtils.getJsonObjFromResource
/* 这里直接获取到了文件路径 */
(BookController.class.getClassLoader().getResource("static/json/book_nav.json").getPath());
return "book";
}