How would that other servlet or JSP obtain a reference to the request in order to change the attribute?another Sevlet (or JSP2) change the attribute
Not quite - the forward method will return once JSP1 has totally finished executing. If any Java method didn't return, the whole call stack would be ruined! Java methods always return, without exception. The difference is that in this case it blocks until the called resource has finished its work. And your second statement is therefore untrue: the rest of the service method will execute, but only once the forward has completed. You are free to put whatever code you want in your servlet after the forward, except that it shouldn't modify the response any further (though it can, if you want some exceptionsOnce you give RequestDispatcher.forward(req,resp), the control goes to the JSP1. Nothing in the service method afer the forward statement will execute.
Yes - the whole point here is that each request is handled by one thread in the container, and that thread's execution can only be in one Java method at a time (due to the way the call stack is structured) - this means only one component (servlet/JSP) in the thread can be executing at any one instant, so your request scope is thread-safe - it belongs only to the executing thread.So in this way request attribute are thread safe, as at one time only one component is reading or writing the request attributes.
Yes, that's right. The JSP translator adds some housekeeping code into the servlet so any content you wrote in the rest of the page is skipped. For example, the Resin 3.1.3 container translates this simple JSP:into the following servlet snippet:I put the relevant bit in bold, so you see using <jsp:forward> causes the JSP's service method to return execution once the forward completes. It uses the if(true) bit to stop the compiler complaining about "unreachable statements" below the return - some containers may just remove all the lines below it altogether!However what is the behavior when we call jsp:forward from a jsp page 1?. The control goes to the forwarded jsp page 2. Then the rest of the jsp page 1 after the forward does not execute? Is that correct?
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |