How come temp can be assigned for both Bean and a Variable?
Hi, here is my understanding. The jsp:useBean action does several things: - declares a local variable with name temp and type String inside _jspService method - searches for an attribute in the page scope with name "temp". if it exists, the associated object is assigned to variable temp. - if such an attribute does not exist, a new String object is created, placed into the page scope with name "temp" and assigned to the temp variable. So in any case, temp will point to an object of type string after this action completes. Thinking in JAVA, the variable temp is just a normal method local variable and can be manipulated inside <% %> scriptlets. The scriptlet <% temp="temp"; %> makes temp point to a new String object. So you manipulate the same variable, but change the String object it points to. Hope this helps, Bernd SCJP
Thiru, We can not have 2 vars with the same name in the same visiblity scope. In the above code, we are not declaring 2 vars with same name as "temp". There is ONLY ONE varablie inside _jspService(HttpServletRequest,HttpServletResponse) method. The String var can take ANY value. In java we do not restrict a String var taking the same value as its name. Right? In the above code it's just so happened a String var named 'temp' takes a value of 'temp'. The following code will not work since it tries to declare a 2nd var named as 'temp' in the same _jspService(req,res) method. Please take a look at the generated java file for the above jsp to have better understanding.
This code too will not work.
Regards, Maha Anna [ December 16, 2002: Message edited by: Maha Annadurai ]