This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
What do we mean by that 'call to forward() method of requestdispatcher is transparent to the browser'? I tried both forward() of rd and response.sendRedirect() , but the url in the browser doesn't get changed and it keeps the url of the servlet which contains these calls. ashok.
May be you are missing something . The Browser's URL in case of response.sendRedirect() DOES get changed .
....call to forward() method of requestdispatcher is transparent to the browser...
When call to forward() of requestdispatcheris encountered , the request is transfered to another resource JSP/HTML/Servlet etc ( specified in requestDispatcher's constructor ) . The response generated by this new resource is what is sent back to the client But response.sendRedirect() send back a new URL to client , which it should request . Client request for new URL and it is served by web-container . So client is invovled in all this I guess above points make it clear , why forward() is transparent to client , while sendRedirect() is not
And to check this , you can use following setup Make a directory 'rdapp' in your server's 'webapps' folder . In WEB-INF/classes , place following two files RD1.java
Save WEB-INF/web.xml as:
Make two html files in your 'rdapp' folder ( you choose their contents ) : - rd1.html - rd2.html