This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

2) getContext - absolute path

 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.14.2.8.1


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
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here goes..........
Forwarding a request to a servlet in my Root web-app to the examples web-app......


- satya
 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
This parrot is no more. It has ceased to be. Now it's a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic