File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes jsp bean issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp bean issue" Watch "jsp bean issue" New topic
Author

jsp bean issue

archana vishwanath
Ranch Hand

Joined: Mar 09, 2004
Posts: 39
<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

Joined: Mar 18, 2004
Posts: 572
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

Joined: Apr 23, 2004
Posts: 1
Yes, the bean must be in a package.
archana vishwanath
Ranch Hand

Joined: Mar 09, 2004
Posts: 39
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

Joined: Jan 10, 2002
Posts: 60057
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp bean issue
 
Similar Threads
Shubha
help bean!
jsp:useBean tag Rules
what's wrong with 'AbstractClass', if object is there
jsps and classes