例如, java ee项目位于 C:\ ABC。
servlet位于 C:\ ABC \ src \ demo \ HelloServlet.java中。
public void doGet(..,..){
//how can I get the absolute path of the project(C:\ABC\)
}
答案 0 :(得分:2)
您可以尝试:
request.getSession().getServletContext().getRealPath("");
答案 1 :(得分:0)
使用:request.getServletContext()。getRealPath(“。”);