This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp declaration

 
Rafi Fareen
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys,

jsp declaration is invoked once when the jsp page is loaded or invoked as per each request?



will result same number on any number of refreshes. same or different browser.



 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, the declaration is moved out of the service method, hence you are creating an instance variable.
Since it is not static, with every load of the servlet the number would be different, but, Servlets are Singletons, so there is only one instance that is reused for subsequent requests, and therefore your number will not change.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Servlets are Singletons


what ? Servlets are not Singletons just because container creates one instance. Singleton is separate subject.


 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems like it would have been quicker to just try it.

Since it's server-side code the browser is irrelevant.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Balu Sadhasivam wrote:
Servlets are Singletons


what ? Servlets are not Singletons just because container creates one instance. Singleton is separate subject.




Whatever way you put it, there is one instance of the Servlet, not more, this is ensured by the container. It is not the fully fledged Singleton pattern, but the idea is the same - One Instance.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65535
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sebastian Janisch wrote:Whatever way you put it, there is one instance of the Servlet, not more, this is ensured by the container. It is not the fully fledged Singleton pattern, but the idea is the same - One Instance.


Firstly, I have to agree with David. Simply creating one instance of a class does not qualify it as a Singleton. That's the name for a distinct pattern.

Moreover, the container can create multiple instances of the Servlet in some circumstances, so even then, the "singleton" moniker is inappropriate.

But all this has nothing to do with the original topic, so if any one wants to pursue the "what is a singleton?" question, please open a new topic in the Patterns forum.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65535
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To the original poster: you do realize that scriptlets and scriptlet expressions are no longer deemed acceptable in JSPs, right?
 
Rafi Fareen
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:To the original poster: you do realize that scriptlets and scriptlet expressions are no longer deemed acceptable in JSPs, right?


hehe i have recently started studying jsp, so i'm just going ahead and reading whatever comes in the book.
if scriplet and expression are not longer in style, than what are the replacements??

soon i will be start with mvc and javabeans :p using this book (core servlet and javaserverpages volume 1, by core technologies) .....
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35757
412
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rafi Fareen wrote:hehe i have recently started studying jsp, so i'm just going ahead and reading whatever comes in the book.
if scriplet and expression are not longer in style, than what are the replacements??

MVC to minimize the logic in the JSP and EL for the rest.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSTL is the replacement.

I hope you're using the latest edition of the book. And it's not "by Core Technologies", it's by Marty Hall and Larry Brown.
 
Rafi Fareen
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:JSTL is the replacement.

I hope you're using the latest edition of the book. And it's not "by Core Technologies", it's by Marty Hall and Larry Brown.


i have got it now .... thanks for the information.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!