• Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp + thread safe  RSS feed

 
david allen
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have a bean called login and it has two variables at class level called username and password. Is there the potential problem that if two people login at the same time the variables username and password could contain incorrect values.
If this is the case is the only way around this to declare the page thread safe? So in a way anypage that uses a helper class with variables at class level(not declared in function) should include the thread safe attribute
Regards david
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That greatly depends upon how the bean is created and stored. Are you creating it in a servlet and passing it to the page in request context? Session context? App context? Using <jsp:useBean> to create the bean? In what scope?
bear
[ August 22, 2003: Message edited by: Bear Bibeault ]
 
david allen
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry ,
What I was asking was about instance variables and not class variables.
My bean is called login. It has two instance variables ( usernanme, password) that are private. The actual bean is being called from a jsp page.
Here is my understanding of it for the various levels of scope.
Page: the bean instance variables are available to that page and therefore can not be overridden by another user accessing the same page.
Application: the bean instance variabels are available to whole application and therefore can be overridden by another user accessing the same page.
session: the bean instance variables are available to that session.
request: not sure about this one.
So my theory is if the bean is used at page level and user1 logs on at the exact same time as user 2 then they will each have their own instance of the bean and therefore cannot override the beans instance variables.
is this right?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct, two beans with page scope will never interfere. The distinction between page and request scope is that the request scope bean will be available if the request is forwarded while the page scope will not.
Bill
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!