my dog learned polymorphism*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "jsp:useBean Topics" Watch "jsp:useBean Topics" New topic
Author

jsp:useBean Topics

Michael Santosa
Greenhorn

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)
pageContext.getAttribute("school",PageContext.APPLICATION_SCOPE);
if ( school == null )
{
_jspx_specialschool = true;
try
{
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
is.
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...
Anonymous
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: http://aspose.com/file-tools
 
subject: jsp:useBean Topics
 
Similar Threads
what's wrong with 'AbstractClass', if object is there
Bean standard action doubt
Session bean across more than one JSP page
EL displaying as text
About jsp:useBean tag