Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

different scope of javabean  RSS feed

 
Nailao liuage
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all:
I don't know about this two line code:
1. <jsp:useBean id="liuID" scope="request" class="com.myClass" />
2. <jsp:useBean id="liuID" scope="session" class="com.myClass" />
can you tell me what different about:scope="request" and scope="session".

thanks a lot
liuage
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nailao
Think of scope for a bean as meaning the same thing it does for variables in code - meaning the variable is accesible, or can be seen.
When the useBean tag is encountered the container first checks within the scope listed to see if a bean of the same name already exists, if not it creates a new one and returns the reference.
So in:
<jsp:useBean id="myBean" scope="session" class="com.myClass" />
the container will check the session object for a bean of the name 'myBean'. The same aplies to the other scopes too. Page is the current JSP, Request is the current ServeletRequest object that was passed to the JSP, and application scope is the ServletContext.
Hope that helps
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!