• 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

some confusions

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi to all...

I have some confusions as follows.....

1.what happens if we try to write some text (out.println("hello")) after requestDispatcher.forward()...
whether exception get thrown or just the output of forwarded resource get displayed??

2.what happens if we try to write some text (out.println("hello")) after response.sendRedirect()...
whether exception get thrown or the resource get redirected succesfully??

3.If there is tag handler class which extends TagSupport not BodyTagSupport and whose doStartTag
method returns EVAL_BODY_BUFFERED...then is that code succesfully compiled or exception get thrown???

4.During forward on ServletContext if we had used relative path in requestDispatcher and then do forward on that object...what happens in this case....

5.Is */* a valid url pattern for servlet mapping?


please help me.......

thanks in advance
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you try any of this yourself. I think the best way to find out the answer is to try this yourself, that way you'll get the answer and get some practice at the same time...
 
geet rahane
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yor are right .......that i should have to try this..i will try it...but due to some problems in my pc ,it is not possible to try them now..so now please help me...........
 
Ankit Garg
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

geet rahane wrote:1.what happens if we try to write some text (out.println("hello")) after requestDispatcher.forward()...
whether exception get thrown or just the output of forwarded resource get displayed??

2.what happens if we try to write some text (out.println("hello")) after response.sendRedirect()...
whether exception get thrown or the resource get redirected succesfully??



I think in both the cases, the client will get normal response (the forwarded content and redirected page) and internally an exception will also be thrown on the server but the client will have no knowledge about it.

4.During forward on ServletContext if we had used relative path in requestDispatcher and then do forward on that object...what happens in this case....



You'll get an IllegalArgumentException at runtime.

5.Is */* a valid url pattern for servlet mapping?



No, the mapping URL must start with /

(Sorry I skipped the custom tag question, I'm not good at it )
 
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Geet.

3.If there is tag handler class which extends TagSupport not BodyTagSupport and whose doStartTag
method returns EVAL_BODY_BUFFERED...then is that code succesfully compiled or exception get thrown???

It will not compile.
 
Chinmaya Chowdary
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ankit.

I think in both the cases, the client will get normal response (the forwarded content and redirected page) and internally an exception will also be thrown on the server but the client will have no knowledge about it.

After forward if we use like if exception occurs internally at first statement, the second will not be executed.
Here is executing. Can you please explain internal working? Thankyou.
 
Ankit Garg
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as I know, there should have been an exception as given here. I tried it and it doesn't give any exception in Tomcat or Glassfish. Maybe Christophe can throw some light ...
 
geet rahane
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot !!!
 
Chinmaya Chowdary
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply.
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


why would that throw IllegalStateException exception ? It is thrown when you flush the buffer and then call response.sendDirect() or request dispatcher. There is no behavior to say otherwise as Printwriter.println() does not throw IllegalStateException .
 
Chinmaya Chowdary
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Balu, thanks for the reply. What happens when the container sees after forward? Can you please explain? Thankyou.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

what it does to the out buffer that exists before calling forward ? it ignores the entire buffer, similarly it ignores after that.
 
Chinmaya Chowdary
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thankyou.
 
Ankit Garg
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

what it does to the out buffer that exists before calling forward ? it ignores the entire buffer, similarly it ignores after that.



More specifically, it clears the buffer before the forward, the other part is correct.

Now actually when the call to forward returns, the PrintWriter is already closed. Additional calls to out.println() result in nothing. This is written in the documentation of PrintWriter class

Methods in this class never throw I/O exceptions, although some of its constructors may.



So if you try to call getOutputStream() after a forward, you'll get an exception because the forwarded JSP would've already called getWriter() on the response (If you forward the request to a Servlet which retrieves the OutputStream, then calling getWriter after the forward will result in an exception). I even tried something like this which proves what Balu said (it was unexpected for me, I expected IOException till I saw the docs )

 
Get me the mayor's office! I need to tell her about this 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