• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

jsp + thread safe

 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic