Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp second request also make new object

 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my jsp filw


i ma using netbeans
when i run this file it shows output " INN OUT".
But i copy and past the url in a new tab.then also it gives same output.
when second request comes it doesnt creat a new object of person.so it must give old object values.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65113
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The requests are distinct and separate. A new Person object will be created for each request.
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that means if one client send a two request to the jsp it creates two instance for that requests.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65113
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't matter where the requests come from. Each is a distinct and separate request and the way that JSP is written, a new Person instance will be created for each and every request.
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is because you're using a scope of request. If you want the same instance for all requests made by the same user, you probably want to use a scope of session.

Otherwise, I'm not understanding what you're asking (your post title is a "statement", not a "question").

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic