hi, JSP declaration is like <%! ... %> and scriplets would be like <% .. %> whatever is there in declaration gets inserted into our servlet and whatever is there in the scriptlet is inserted into the service method of the servlet. i know that if this the case then we should not put variables that might be shared across multiple servlet threads into the declaration. but still if someone can give me an example of usability of both of these then it would be great help to me. if i'm to give an example of this then i would say that "if we want to determine the how many requests came for the same JSP page then we can put a counter variable into the declaration which becomes a part of the sevlet instance and so we can increment it in the scriptlet code to keep counter updated". like, <%! int counter = 0; %> <% counter++; %> am i right? regards maulin.
posted 15 years ago
Your example is not thread safe for there could be multiple threads trying to update the counter. You need to have "synchronized" access code for such variables. -Srini
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads