• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp bean issue

 
archana vishwanath
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<jsp:useBean
id="db"
class="demo.DbBean"
scope="application"/>

<%
Connection con=db.getconnection();
%>
Friend's im confused with the scope element here,In this example im declaring the scope to be application.
So ,will I be able to use my bean in all my other jsp files ,without using
<jsp:usebean> tag in those pages.
But its not working,Pls advice me on this.If the scope is not mean for
something like this ,then what's it for?

 
Ali Gohar
Ranch Hand
Posts: 572
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The scope in which the Bean exists and the variable named in id is available. The default value is page. The meanings of the different scopes are shown below:

page - You can use the Bean within the JSP page with the <jsp:useBean> element or any of the page's static include files, until the page sends a response back to the client or forwards a request to another file.

request - You can use the Bean from any JSP page processing the same request, until a JSP page sends a response to the client or forwards the request to another file. You can use the request object to access the Bean, for example, request.getAttribute(beanInstanceName).

session - You can use the Bean from any JSP page in the same session as the JSP page that created the Bean. The Bean exists across the entire session, and any page that participates in the session can use it. The page in which you create the Bean must have a <%@ page %> directive with session=true.

application - You can use the Bean from any JSP page in the same application as the JSP page that created the Bean. The Bean exists across an entire JSP application, and any page in the application can use the Bean.
 
Milan Kuchtiak
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the bean must be in a package.
 
archana vishwanath
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have wrongly interpreteted my question ,My question is simple
Should I use the <jsp:usebean> tag in every page where im using the
bean or not,
Ater declaring the scope to be "application"
I have declared my bean scope as application in my first page.But in my second page unless,I write the <jsp:usebean>tag once again im not able to acess the bean,What may be the problem??
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your understanding of the useBean tag is faulty. The scope you declare controls the accessibilty and lifetime of the bean. You must still use the useBean action on each page to "hook up" the bean to the id with which it will be referenced on the page.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic