You can have different web applications deployed in same web server. In that case, there are more than one ServletContext(s) exist in same web server(for each web application). If you want to access the servlet context of other applciation deployed in same web server from your application, you can use this method.
Joined: Dec 23, 2003
Thanks, Anil .
Furthermore, if I have ServletContext servletCtx = "my-web" ; RequestDispatcher rd = servletCtx.getRequestDispatcher("/login.jsp"); rd.forward(req, res);
What will happen ?
In my understanding, it will be same as the user rquest "my-web/login.jsp" in his web browser. but this time, the URL will not show up in browser address bar.
It won't compile. ServletContext servletCtx = "my-web";
You're trying to assign a string to a ServletContext variable.
Just use: getServletContext().getRequestDispatcher("/login.jsp");
This will get the context object for the current app.
And yes, the user will see the login.jsp in their browser. The browser's address window, however, will still show the original address for this servlet. This all takes place on the server without the browser's knowledge.