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.