Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
I know that if I do a request.getContextPath I can retrieve this: "/applicationName/folderOne/folderWhatever" but I just want the application Name.
Is there some way to do this?
Why don't you use String utility methods to parse the above context path string to get application name(as you know the first name is always going to be application name)? I know this is a basic thing for anyone to do. What made this idea didn't work for your requirement?
(OCEEJBD6, SCWCD5, SCDJWS, SCJP1.4 and Oracle SQL 1Z0-051)
The one in the HttpServletRequest gives me this: "/seeti/folder/folder2"
How do I access the method from the ServletContext object? Actually, how to I access the ServletContext object at all?
I can definitely do this...and it is the best option right now. However, I was just very curious as to whether or not there was a more straightforward way to do it with JavaServlets that I was just not aware of yet. But thanks!
The ServletContext object is contained within the ServletConfig object, which the Web server provides the servlet when the servlet is initialized.
See Also: Servlet.getServletConfig(), ServletConfig.getServletContext()
If you can be sure that the first part of the URI is the application, couldn't you find the application name simply by splitting the path on the '/', and look for the first (non-empty) item? This is typically what I do to retrieve the application name.
In preparing for battle I have always found that plans are useless, but planning is indispensable. -- Dwight D. Eisenhower
As you may already know... the EAR contains >= 1 WAR and each WAR has a unique context path. This context path is what is part of the URL. This allows the web container to delegate the requests targeted to specific web applications.
Now one can keep the request context path same as the application name. In that case you can get the request context path from HTTP Request object.
You can maintain a mapping property file, which matches the context path to application names.
Here is a sample of application.xml file. This file get bundled in the EAR file and is present under META-INF folder.
The web request context path is mentioned here as well as in the "ibm-web-ext.xml" file, which gets bundled in the WAR file.