How can a class get the name of the WAR file that is using it?
This is for diagnostic purposes.
To rename the WAR file: Use the rename command to rename the WAR file. Enter the command without the line break. Where custom_name is the context root or custom application name you choose.
Static HTML files and JSP are stored at the top level of the WAR directory. The top-level directory contains the WEB-INF sub-directory which contains the following: Server-side classes (Servlets, JavaBean components and related Java class files) must be stored in the WEB-INF/classes directory.
In software engineering, a WAR file (Web Application Resource or Web application ARchive) is a file used to distribute a collection of JAR-files, JavaServer Pages, Java Servlets, Java classes, XML files, tag libraries, static web pages (HTML and related files) and other resources that together constitute a web ...
The WAR file (Web Application Resource or Web Application ARchive) is a container for JAR files, JavaServer Pages, Java Servlets, Java classes, XML files, tag libraries, static sites (HTML and associated files), and other resources that make up an online application.
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 application. In most cases, it defaults to the name of the war file, unless you configure it explicitly. So if you have foo.war, then you'll access it at http://localhost:8080/foo/
, and the above function will return "/foo".
in servlet
String warName = new File(getServletContext().getRealPath("/")).getName();
you can use this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With