• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

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

 
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IDE problems should be posted in the IDEs forum. I'm moving this post there for you.
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 650
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 650
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, yes, that fixed it. Thanks again for all the help.
 
So there I was, trapped in the jungle. And at the last minute, I was saved by this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic