This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I am not 100% on this so maybe someone else can comment.
However if you use the URL in example 1 http://localhost:8080/scwcd/Tomcat then you are forcing the container to go to the DD and see where it should direct the request to.
If on the other hand (and this is where I am not 100% sure) you type in the url as per example 2 http://localhost:8080/scwcd/HFSJ/ch07/TestInit.jsp it is up to the container, and in this case the container thinks it has enough information to direct you query straight to the requested resource 'TestInit.jsp' and therefore doesn't need to go to the DD thus the init-param name/value pair is not given to the jsp after it is compliled.
I have the feeling that I have read somewhere this is what happens.
Just out of curiosity if you go to the url in example 1 and then without restarting Tomcat (I assume that Tomcat is the container you are using) go to the second url you typed in - what happens?
Both the URLs are handled by diff. Servlet instance. When you call the JSP with Tomcat it served by the servlet instance which have a init parametres as per DD. When you call the JSP with original name, it will serve by diif. instance which do not have init parameters.
Hi Narendra, I know that a jsp gets translated into servlet, but i am not aware of the different instance of a jsp trying to serve the request. I have compared the java code generated by tomcat in the case of url1 and url2 and the codes are same.
If two different instance are serving the request, how they are different. can you tell more on this !
Joined: Dec 04, 2004
The code for the class are not different. The generated servlet class is same, but the container create multiple instances for the same class. In your case one is for the <servlet> defination and another for implicit .jsp defination.
Hello, It is very nice. I have one question: what is on RequestDispatcher's forward? Is it used the DD?
Joined: Dec 04, 2004
It id sepend on how the RequestDispatcher object is constructed. If you are using the URI mapped as definded in DD, it will use the Servlet instance with init param. If you are using URI using directly JSP file it will use the instance without init params.
Basically two (not considering distributed / SingleThread models) instances are craeted as you have to pass two different ServletConfig objects to init method.One having the init parameters and one without it.