aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes <jsp:useBean ... type= is not finding the bean class" title="Pirate Day" /> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "<jsp:useBean ... type="package.class"> is not finding the bean class" Watch "<jsp:useBean ... type="package.class"> is not finding the bean class" New topic
Author

<jsp:useBean ... type="package.class"> is not finding the bean class

Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
Hello friends.

I'm reading the book Core Servlets and JavaServer Pages, and specifically am going through the section on MVC with Servlets and JSP. I'm having a problem with resolving the Java Bean class both in the IDE (Eclipse) and by the container at runtime.

I have created a Java Bean in the package "com.mypackage". The Bean is called MemberInfoBean.
I have created a Servlet in the package "com.mypackage". The Servlet is called MemberSignup.
Finally, I have created a JSP page to use as the View, it is WEB-INF/memberSignup.jsp

I believe the MemberInfoBean class meets the requirements for a Java Bean, in that it contains only private member variables, public accessor methods and no constructor (so the default, zero-arg constructor will be generated). I show it in the following listing, although I've limited it to just three of the member fields to keep it brief:
The servlet creates an instance of the Bean class if one is not found in the session, then forwards the request on to the JSP page. The following is a snippet from the doGet() method of the servlet:
Note that the above compiles and runs fine. Again, both the Servlet and the Java Bean are in the same package.

In the JSP page (WEB-INF/memberSignup.jsp), I have the following:
First, the Eclipse IDE shows this line with an error saying Undefined Type: com.mypackage.MemberInfoBean.
If I deploy the application anyway, when the Servlet attempt to forward to the JSP page, the container says: An error occurred at line ... of ...memberSignup.jsp, and the error is: com.mypackage.MemberInfoBean cannot be resolved to a type.

I inspected the WAR file created by Eclipse, and both the Servlet and Java Bean classes are in WEB-INF/classes/com/mypackage.

There are two problems:

1. Why doesn't the IDE know about the Java Bean class, and;
2. Why can't the container find the Java Bean class at runtime.

Any help would be greatly appreciated.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Looks fine to me .

Mark wrote: Eclipse IDE shows this line with an error saying Undefined Type: com.mypackage.MemberInfoBean


I doubt on your creation of package structure. please verify this
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61216
    
  66

IDE problems should be posted in the IDEs forum. I'm moving this post there for you.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
Bear Bibeault wrote:IDE problems should be posted in the IDEs forum. I'm moving this post there for you.

Thank you Bear, but I'm more interested in the runtime error. Can we please leave this in the Servlets forum?
I don't think the problem is with the IDE, as I've inspected the application war file, and the classes are all in the correct locations. I think there is another problem.

Thanks,
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
Ugggggh! The error sounds like there's a problem with the package declaration for my class. As a result, I checked it several times, very carefully, etc. - Well, that wasn't enough. I had transposed two characters in the package name. I can't believe how many times I looked at that and didn't see it.

I haven't fixed it yet, but fully expect it will solve the problem. Thanks for the help and sorry for the mistake.

Best Regards,
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
Okay, yes, that fixed it. Thanks again for all the help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: <jsp:useBean ... type="package.class"> is not finding the bean class