File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes jsp:useBean Topics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "jsp:useBean Topics" Watch "jsp:useBean Topics" New topic

jsp:useBean Topics

Michael Santosa

Joined: Mar 13, 2002
Posts: 19
When I put this line at my JSP page :
<jsp:useBean id="school" scope="application" class="translator.MyTranslator"/>
Then it will compile it into servlet like this
using TOMCAT :
translator.MyTranslator school = null;
boolean _jspx_specialschool = false;
synchronized (application)
school= (translator.MyTranslator)
if ( school == null )
_jspx_specialschool = true;
school = (translator.MyTranslator) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "translator.MyTranslator");
catch (ClassNotFoundException exc)
throw new InstantiationException (exc.getMessage());
catch (Exception exc)
throw new ServletException (" Cannot create bean of class "+"translator.MyTranslator", exc);
pageContext.setAttribute("school", school, PageContext.APPLICATION_SCOPE);
It means the school bean is always act
as "local variable".. whatever its scope
So when I want to use this instance of
bean again in another JSP page,
then I put the same code
<jsp:useBean id="school" scope="application" class="translator.MyTranslator"/>
Then I will get the same instance, right ?
Please correct me if I am wrong...
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
<jsp:useBean id="school" scope="application" class="translator.MyTranslator"/>
instaed of class use type attribute
I agree. Here's the link:
subject: jsp:useBean Topics
It's not a secret anymore!