• 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
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

jsp:useBean tag

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi everybody,
If I access the <jsp:useBean ...> tag for the same Bean object 5 times how many instances of that Bean are created?
eg. <jsp:useBean id="xx" scope="session" class="pac.Abean">
 
Ranch Hand
Posts: 126
Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have a problem with usebean tag in JSP. My jsp is unable to find the bean. m using tomcat and have placed the bean and jsp file in /examples/jsp.
my jsp file looks like this.....<html>
<head>
<title>
Color Demo Example
</title>
</head>
<body>
<!-- This page generates a series of rainbow colored letters -->
<!-- It uses plain method calls to the Bean -->
<%@ page language="java" %>
<%! char c = 0; %>
<jsp:useBean id="letterColor" scope="application" class="AlphabetCode" />
<%
for(int i=0;i<26;i++){
for(int j=0;j<26;j++){
c=(char)(0x41+(26-i+j)%26);
Character thisChar=new Character(c);
letterColor.setCharacter(thisChar.toString());
%>
<font color=<%=letterColor.getColor() %> >
<%=letterColor.getCharacter() %>
</font>
<%
}
%>
<br>
<%
}
%>
</body>
</html>
let me know where i have gone wrong.
nitin
 
amit sanghai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi Nitin,
I think u should place the page directive tag at the very beginning of ur file.

Can somebody please give the answer to my question?
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by amit sanghai:

Hi everybody,
If I access the <jsp:useBean ...> tag for the same Bean object 5 times how many instances of that Bean are created?


jsp:useBean first attempts to locate the bean, and instantiates it only if it isn't found in the specified scope (see 2.13.1 of the JSP 1.1 spec). This is an absolute necessity for request- session- and application-scoped beans, otherwise they couldn't be referenced in multiple pages.
I'm not sure if you are allowed to use the same useBean more than once in a single page. The specification says, apparently unconditionally, that useBean will define "a scripting language variable with the given id in the current lexical scope of the scripting language". That could mean that two useBeans with the same id within the same lexical scope (read more or less: statement block) fail with a compilation error.
Did you try?
- Peter
 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nitin Dubey:
My jsp is unable to find the bean.


"My JSP generates an error. Can someone wade through a hundred lines of unformatted code and tell me what the problem is?"
Sure Nitin, but, erm, what about quoting the error message you got? They usually tell you what the error exactly is.
From your description however I'm willing to bet it's a ClassNotFound error or similar. Your bean .class file needs to go into WEB-INF/classes, not in the same directory as the .jsp.
HTH
- Peter

[This message has been edited by Peter den Haan (edited January 22, 2001).]
 
amit sanghai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi Peter,
I tried using the same jsp:useBean tag wiht the same id and class names. It is giving a fatal error : missing resource in java.util.PropertyResourceBundle.

Thanks,
Bye.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by amit sanghai:

Hi everybody,
If I access the <jsp:useBean ...> tag for the same Bean object 5 times how many instances of that Bean are created?

eg. <jsp:useBean id="xx" scope="session" class="pac.Abean">



it gives error,"duplicate local variable xx.
creating a bean is conditional,means it looks for
if(xx==null){
// create new one
xx= new pac.Abean();
}
if it is already there it won't create any other
Add to this,if we decleare the bean with the same id in other page,we can
access the values set in it.
hope ur question is answered..

Yakub
 
reply
    Bookmark Topic Watch Topic
  • New Topic