Again another new thread to discuss this method....so that we don't cross post with the other methods in the same thread.... Acc to the API in the Spec: SRV.126.96.36.199
getContext(String) public ServletContext getContext(java.lang.String uripath) Returns a ServletContext object that corresponds to a specified URL on the server. This method allows servlets to gain access to the context for various parts of the server, and as needed obtain RequestDispatcher objects from the con-text. The given path must be begin with “/”, is interpreted relative to the server’s document root and is matched against the context roots of other web applications hosted on this container.
Probably worth another example with forward maybe.... Well, forward to another ServletContext on the same server. - satya
Hi Thanx for starting diff posts for the methods... Some things are still confusing..... 1)From the srv 8.4
forward may be called by calling servlet ONLY when no output has been committed to client.
Do we commit output by out.println()? If i am using forward, what is the use of using out.println(); It gives no output and also no error if used. just forwards to the called servlet no matter where u put the out.println statement. 2)How can i check the output data in the response buffer. By using response.isCommitted() and finding if it is true or false.But where shall i put the out.println code?? to verity the specs
If the output exists in the response buffer that has not been committed the content must be cleared before the target servlet's service method is called.If response is committed an IllegalStateException must be thrown.
This paths thingi has led me to ..... wonderland Having fun! yeah sure! thanx faiza
Joined: Jun 03, 2000
Do we commit output by out.println()? When the response (or part of it) is flushed to the client, then we say that the output is committed. Refer to the "autoflush" attribute. This can happen in more than one ways. One, the flush() method is called on the out obj. Secondly, when the buffer is full (and the autoflush is true, which is the default) the server flushes the drain...errr...output to the client. If i am using forward, what is the use of using out.println(); It gives no output and also no error if used. just forwards to the called servlet no matter where u put the out.println statement. That is the intended behavior. Read your other post. This uses the flush() on the out obj and look for the IllegalStateException in your catalina logs. Axel and I had a discussion on this.
2)How can i check the output data in the response buffer. By using response.isCommitted() and finding if it is true or false. I haven't tried this though. But where shall i put the out.println code?? to verity the specs Again the link abv used the out.println() and the out.flush() methods to verify the IllegalStateException, if flushed before the forward() method. Also, out.println() method calls after the forward will be ignored. You shouldn't see them on the client. regds. - satya