How do I get the name of the WAR file?
问题 How can a class get the name of the WAR file that is using it? This is for diagnostic purposes. 回答1: in servlet String warName = new File(getServletContext().getRealPath("/")).getName(); you can use this. 回答2: ServletContext.getContextPath() This returns the context path of the application (or "" for the root context). Within a servlet container, no two applications will ever have the same value for this. EDIT: And for those who don't know what the context path is: it's the URI prefix for the