tags:

views:

129

answers:

2

Hi, Context path in jboss-web.xml is mentioned as /Test, but my war file name is Test-0.0.1. I need this war file name using HttpServlet. Please tell me the function name. i tried getContextPath(), but it returns Test. Thanks

A: 

ServletContext.getContextPath() is the way to get the context path. It can differ from the war-file name, but I can't think of a reason you may need the war file name.

Bozho
+1  A: 

If the WAR is expanded, you could use ServletContext#getRealPath() in combination with File#getName() to obtain the expanded folder name. This will be the same as the WAR file name.

String name = new File(getServletContext().getRealPath("/")).getName();
BalusC