• Post Reply Bookmark Topic Watch Topic
  • New Topic

question about jsp declaration  RSS feed

 
Alex Tosh
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
a very basic question: Why do exist the declaration-tags when it's also possible to use scriptlet-tags to declare variables?
thanks
Alex
 
Debashish Chakrabarty
Ranch Hand
Posts: 231
Firefox Browser Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is somethings from my scrap-book:
  • A declaration is a complete logical unit of work.
  • Declarations don't produce any results into the output buffer.
  • Declarations are initialized when the JSP page is initialized.
  • Code within declarations is made available to other declarations, expressions and scriptlets.

  • Variables created within a declaration block become instance variables. Since JSP containers tend to only make one instance of a page to share requests against, this can mean that all current instances of the JSP page have access to the same variable. In other words, if your page is currently being accessed at the same time by 10 users, those 10 users are sharing one variable. For all practical purposes, you are creating a class variable. If you want to avoid this, you can create variables within your scriptlet block. Variables declared within a scriptlet block are local to that script block.
  • You can also set

  • <%@ page isThreadSafe="false" %> to get around this issue. However, using the isThreadSafe property has serious performance issues on high traffic sites. If you want to use your variable as a class variable, we recommend that you declare it as such and don't count on this behavior as being the rule.
  • You can also declare class variables and functions in a declaration block.


  • Hope this helps
     
    Alex Tosh
    Greenhorn
    Posts: 13
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Debashish,
    this helps indeed to understand the difference; thank you
    best regards
    Alex
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!