tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rick Horowitz <rhorow...@ni4u.com>
Subject Re: JSP exception question...help needed
Date Thu, 14 Sep 2000 22:27:25 GMT
Bill, Tim,

Thanks for your explanations...I debugged into the Tomcat code. Here's a
more in-depth explanation of what's happening...

In my .java file that was generated from the .jsp file
"_0002fjsp_0002flogin_0002ejsplogin_jsp_0":

...as the code shows, if the errorsMap attribute does not yet exist, the
generated jsp/java file attempts to instantiate it by calling
Beans.instantiate() with the current ClassLoader and the name of the
bean.

                    errorsMap= (java.util.HashMap)
                   
pageContext.getAttribute("errorsMap",PageContext.REQUEST_SCOPE);
                    if ( errorsMap == null ) {
                        _jspx_specialerrorsMap = true;
                        try {
                            errorsMap = (java.util.HashMap)
Beans.instantiate(this.getClass().getClassLoader(),
"java.util.HashMap");
                        } catch (Exception exc) {
                             throw new ServletException (" Cannot create
bean of class "+"java.util.HashMap");
                        }
                        pageContext.setAttribute("errorsMap", errorsMap,
PageContext.REQUEST_SCOPE);
                    }

...the code picks up on Beans.java, where it attempts to use the
ClassLoader to load the class for the bean.  If the beanName doesn't
have the package prefix, the class load fails, triggering the error
messsage, which btw sucks because it is masked by the catch in the
jsp/java file above that issues " Cannot create bean of class
"+"java.util.HashMap", but not the classloader error...anyone doing
Tomcat development agree with this...would be nice to let the original
exception show...somewhere, perhaps if we are in debug mode, output the
full msg.

	    try {
	        if (cls == null) {
	            cl = Class.forName(beanName);
	        } else {
	            cl = cls.loadClass(beanName);
	        }

Thanks again,

Rick Horowitz

Tim Moore wrote:
> 
> Because the imports only apply to compile-time name resolution, but the
> jsp:useBean tag loads the class at runtime using Class.forName or something
> equivalent.
> 

William Brogden wrote:

I think it because the reflection mechanism that creates the 
Bean needs the full package qualified name. Import statements
only affect in-line code. Thats my theory anyway.....


> --
> Tim Moore / Blackboard Inc. / Software Engineer
> 1899 L Street, NW/ 5th Floor / Washington, DC 20036
> Phone 202-463-4860 ext. 258 / Fax 202-463-4863
> 
> > -----Original Message-----
> > From: Rick Horowitz [mailto:rhorowitz@ni4u.com]
> > Sent: Thursday, September 14, 2000 5:24 PM
> > To: tomcat-user@jakarta.apache.org
> > Subject: Re: JSP exception question...help needed
> >
> >
> > Bingo!! But why?? Doesn't make sense to me..
> >
> > Thanks a million!!
> >
> > Rick
> >
> > William Brogden wrote:
> > >
> > > Rick Horowitz wrote:
> > > >
> > > > Unfortunately, that did not help. I already have
> > java.util.* on the
> > > > imports. Thanks anyway for trying :) Anybody else have
> > any idea why I'm
> > > > seeing the problem outlined below?
> > > >
> > > > TIA...Rick Horowitz
> > >
> > > In spite of the fact that you have included java.util.HashMap, you
> > > still have to give the complete package in your JSP tag
> > >
> > >  <jsp:useBean id="errorsMap" class="java.util.HashMap"
> > scope="request"
> > > />
> > >
> > > > > > javax.servlet.ServletException:  Cannot create bean
> > of class HashMap
> > > > > >       at
> > org.apache.jasper.servlet.JspServlet.service(JspServlet.java:386)
> > > > > >       at
> > javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> > > > > >       at
> > >
> > > --
> > > WBB - wbrogden@bga.com  Chief Scientist, LANWrights, Inc.
> > > Java Programmer Certification information and mock exam
> > > at  http://www.lanw.com/java/javacert/
> >

Mime
View raw message