Originally posted by Tarun Yadav:
[1]. Any code after the forward call will not be executed.
Originally posted by Ben Souther:
That part is not true.
A call to forward does not stop execution of the method that called it.
What happens exactly? Well, it's Java code. So after one line of code is executed, the next line of code is executed. It's still Java even though it's being run in a servlet container. Don't let that distract you; it's just Java code and follows the same rules as any other Java code.Originally posted by Tarun Yadav:
So what happens exactly then? Could you elaborate? Perhaps an example? In any case, you can't do anything with the response since that would throw an exception. Do you mean that apart from that you can have something else happen in the method?
Originally posted by Paul Clapham:
What happens exactly? Well, it's Java code. So after one line of code is executed, the next line of code is executed. It's still Java even though it's being run in a servlet container. Don't let that distract you; it's just Java code and follows the same rules as any other Java code.
So in particular, if you want to do something after you call the forward() method, go ahead and do that. But as you say, you can't do anything with the response.
Working......<br />==============================<br />Playing......<br />==============================
Originally posted by paritosh ranjan:
As any output buffered before the call is cleared.
How will I achieve the functionality of redirecting the user to different pages depending on the user input?
I think this code will make clear what I want to achieve.
I want to redirect the user to different pages according to user input.
However, the page is redirected without even asking the user input(I think the reason is that the buffered output is cleared before the forward).
So, how will I achieve that functionality.
Originally posted by paritosh ranjan:
Tarun
Its not necessary to split input and forward in different resources.
The whole thing can be encapsulated in a single jsp page by applying a little bit of logic.
See this code:
I used the same jsp page for taking input and forwarding.
Bear
Thanks for the article.
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Won't you be my neighbor? - Fred Rogers. tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|