Java – access Tomcat context path from Servlet
•
Java
In my servlet, I want to access the root of the context so that I can do some JavaScript scaling
Minify can be done as part of the installation process, but I want to do this when the servlet starts to reduce the implementation cost
Who knows how to get the context directory so that I can load and write disk files?
Solution
This should give you the real path you can use to extract / edit the file
Javadoc Link
We did something similar in the context listener
public class MyServlet extends HttpServlet { public void init(final ServletConfig config) { final String context = config.getServletContext().getRealPath("/"); ... } ... }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码