| Author |
State true or false...
|
Ajith Kallambella
Sheriff
Joined: Mar 17, 2000
Posts: 5782
|
|
Okay, its my turn to ask now I would like someone to validate( state true/false ) these statements. All are about JSP. Scriptlets get included into service() method of the generated servlet. Variables used inside a scriptlet are local variables and hence thread safe. Declared variables outside the scriplet using <!%...%> are included into the compiled servlet as instance variables; as a consequence they are automatically initialized to their default value if no initial value is provided. Delcared variables are not thread safe. By default <%@page isThreadSafe="true" %> for a JSP page. Static variables cannot be declared using the JSP declaration. :roll: I keep bumping into these issues again and again. Perhaps a closure is what is necessary to pass on  [ February 20, 2002: Message edited by: Ajith Kallambella ]
|
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
|
 |
Ashik Uzzaman
Ranch Hand
Joined: Jul 05, 2001
Posts: 2370
|
|
Ajith, you are correct. But i am not sure in a two cases... Declared variables are not thread-safe. Declared variables that are local varibles or decalred in scriptlets are thread-safe. Static variables cannot be declared using the JSP declaration. Can be in declaration statement like --- <!% static int i=0; %> Plz correct me if i am wrong.
|
Ashik Uzzaman
Senior Member of Technical Staff, Salesforce.com, San Francisco, CA, USA.
|
 |
Ian B Anderson
Ranch Hand
Joined: Jun 26, 2001
Posts: 275
|
|
Ok here goes: true - Scriptlets get included into service() method of the generated servlet. true - Variables used inside a scriptlet are local variables and hence thread safe. true - Declared variables outside the scriplet ( using <%!...%> are included into the compiled servlet as instance variables; as a consequence they are automatically initialized to their default value if no initial value is provided. true - Delcared variables are not thread safe. true - By default <%@page isThreadSafe="true" %> for a JSP page. false - Static variables cannot be declared using the JSP declaration. (I tried this on tomcat and it works fine) Hope this helps Ian
|
<a href="http://www.INESystems.com/scbcd/" target="_blank" rel="nofollow">http://www.INESystems.com/scbcd/</a> - SCBCD Exam simulator<br /><a href="http://www.INESystems.com/scbcd/" target="_blank" rel="nofollow">http://www.INESystems.com/scea/</a> - SCEA Exam simulator
|
 |
Madhav Lakkapragada
Ranch Hand
Joined: Jun 03, 2000
Posts: 5040
|
|
Scriptlets get included into service() method of the generated servlet. FALSE. There is no service() method in the generated servlet. It goes into the _jspService(...) method. Just trying to go by the specs. Variables used inside a scriptlet are local variables and hence thread safe. TRUE. Declared variables outside the scriplet ( using <%!...%> are included into the compiled servlet as instance variables; as a consequence they are automatically initialized to their default value if no initial value is provided. TRUE. Delcared variables are not thread safe. TRUE. By default <%@page isThreadSafe="true" %> for a JSP page. TRUE. Static variables cannot be declared using the JSP declaration FALSE. They can be declared and accessed. Ashik: Pl. see the declarations they are to be declared <%! NOT <!%......typo I assume. Thanks. - satya
|
Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
|
 |
Ajith Kallambella
Sheriff
Joined: Mar 17, 2000
Posts: 5782
|
|
Thanks for the clarifications folks. And yes, I fixed the typo
|
 |
ersin eser
Ranch Hand
Joined: Feb 22, 2001
Posts: 1072
|
|
For the last case: "static"
<%! static public int counter = 0; %> The effect of this declaration is to create an integer variable named counter that is shared by all instances of the page's servlet class. If any one instance changes the value of this variable , all instances see the new value. In practice, because the JSP container typically creates only one instance of the servlet class representing a particular JSp page, there is a little difference between declaring instance variables and class variables. The major exception to this rule is when a JSP page sets the isThreadSafe attribute of the page directive to false, indicating that the page is not thread-safe. In this case, the JSP container may create multiple instances of the page's servlet class, in order tohandle multiple simultaneous requests,one request per instance. Now to share a variable 's value across multiple requests under these circumstances, the variable must be declared as static: class variable , rather than an instance variable. when the isThreadSafe attribute is true, which is default, however , it makes little practical difference. Declaring as instance variable saves a little bit typing.
|
 |
 |
|
|
subject: State true or false...
|
|
|