First u get the reference to servlet context using getServletContext() method of GenericServlet or using ServletConfig's getServletContext() method. Now when u get the ServletContext reference , u can invoke the getContext using the method getContext(uriPath). This method allows servlets to gain access to the context for various parts of the server. There may be many servlet applications running on ur server. I mean u can have many entries in ur server.xml, each having a different context path. By using this method u will get the context reference of the other application's context. U can try it out by giving ur servlet context path as specified in the server.xml. Hope this is clear to you
To get the RequestDispatcher you need to set the crossContext to true.
Set to true if you want calls within this application to ServletContext.getContext() to successfully return a request dispatcher for other web applications running on this virtual host. Set to false (the default) in security conscious environments, to make getContext() always return null.
"Rohit India", unfortunately your display name is not valid. Please edit your profile and select a valid display name. We require display names to be two words: Your first name, a space, then your last name. Fictitious names are not allowed.
Secondly: do you really need to make requests across contexts? I've tried it in a few containers and the implementation was pretty poor and buggy.
Other than that, it looks OK. I can't think of anything you haven't already tried.
(no 'sirs' around here, just us ) Drat, I can't find my SCWCD book. I believe the standard response from any vendor is that their implementation of feature X complies to the specification, but the truth is that some parts of the spec are written better than others.
For example, in one container (I forget which, it may have been tomcat) we couldn't get it to work, but in WebSphere we tried to include a JSP from another context, but this happened in another thread so we couldn't control where it got included! It's a long story. Requests in WS come in through a thread pool, and when you make requests across contexts in there implementation, it comes in through the thread pool again.
It's unlikely to be the answer you're looking for, but I'd leave it and go onto something else. I've never heard of anyone using getContext() in a production system.
ServletContext cntx2 = cntx.getContext("/myotherapp"); //Getting the context of other webapp System.out.println("Context of other webpp is =="+cntx2); //Bingo got the request dispatcher RequestDispatcher dispatch = cntx2.getRequestDispatcher("/hello.jsp"); //VOVO Forwarding dispatch.forward(req,res); }
Try running this by specifying your webapp paths. I guess in your code there must be some typo that i am not able to find.
Hope this helps.
Sawan<br />SCJP,SCWCD,SCBCD<br /> <br />Every exit is an entry somewhere.