Now can anyone comment on why the counter value is not 3 and 4 in the second output. Why it is again 1 and 2 when http://localhost:8080/Test/servlet/HelloServlet is accessed ?
Originally posted by Rohit Bhagwat:
Information : It is said that if a jsp page is accessed as a servlet [indicated by the second url above] then a separate servlet instance is created.If we access it as a jsp page then again a new instance is created.
“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook
I believe accessing a generated servlet from both a jsp-file entry in web.xml and hitting the JSP directly will cause two instances of the servlet (with different servlet names) to be created.
Originally posted by Vishnu Prakash:
Aren't we supposed to specify the JSP Page name inside the jsp-file element. can you throw more light on this.
I like to know one more thing. Where to find the generated servlet from the JSP Page.
If you are using Tomcat then you will find the generated servlet in work directory.
Originally posted by Rohit Bhagwat:
I cannot call destroy method in case of tomcat as it is a final method. This is not specified in the specification. However I can write a jspDestroy so that I can write the code that will perform some action that can be necessary before container destroys the servlet. Similarly I can write a destroy method in servlets for the same purpose.
Originally posted by Vishnu Prakash:
What do you mean by work directory ?
Originally posted by Rohit Bhagwat:
I cannot call destroy method in case of tomcat as it is a final method.
Originally posted by Rohit Bhagwat:
We know that jspDestroy method is avaliable for us to override and as such container calls this method from destroy method.So no need to use destroy method, we can use jspDestroy method instead. Thats why they might have made destroy method as final.
Originally posted by Rohit Bhagwat:
Also I tried to use jspDestroy method in the above myJsp.jsp page. But nothing was printed on the console.So the class is not getting unloaded.
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |