Reputation: 6152
I am building jsp pages hosted on tomcat and am wondering if the bean instances referenced in each jsp are stateless / stateful? How do those bean instances come about? Are they (re-)created each time when the page is visited? Do I need to worry about two different users visiting the same page at the same time and getting hold of the same bean instance?
In general I find the interaction between jsp and beans quite confusing so I'd appreciate if someone can refer a tutorial / explanation of those concepts. Thanks!
P.S. How about static fields in the bean classes? Do those values have application scope by default?
Upvotes: 1
Views: 587
Reputation: 2005
The life cycle of the bean is upto the developer or framework the developer choices to use. If you think about a request over multiple pages (or even the same page) unless after you create an instance of a class and store it somewhere then it will be stateless. This is where Java EE session management comes into place, so if you want stateful behavior you would create a instance of the bean and 'persist' it to the session.
If you do persist to a session you don't have to worry about multiple users hitting the application given a session is unique per user and Java EE tries to ensure this.
Upvotes: 0
Reputation: 94645
The bean is Plain Object Java Object and purpose behind development of bean is to store/persist data.
if the bean instances referenced in each jsp are stateless / stateful?
Stateless by default.
How do those bean instances come about? Are they (re-)created each time when the page is visited?
It depends upon the code you've used.
Do I need to worry about two different users visiting the same page at the same time and getting hold of the same bean instance?
Unless you've created a bean with application scope.
Upvotes: 3