Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

State true or false...

 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
     
    Ashik Uzzaman
    Ranch Hand
    Posts: 2373
    Eclipse IDE Firefox Browser Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    Ian B Anderson
    Ranch Hand
    Posts: 275
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
     
    Madhav Lakkapragada
    Ranch Hand
    Posts: 5040
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
     
    Ajith Kallambella
    Sheriff
    Posts: 5782
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks for the clarifications folks. And yes, I fixed the typo
     
    ersin eser
    Ranch Hand
    Posts: 1072
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.

     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic