• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What's wrong with my import declaration?

 
Edmund Yong
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's wrong with the import declaration in my JSP below? Tomcat complains that "The import AddressBean cannot be resolved".

Contents of webapps\beanTest\address.jsp:

<%@ page import="AddressBean" %>

<html>
<body>
</body>
</html>


The AddressBean class is located in webapps\beanTest\classes

The translated servlet code looks ok to me. It has this line:

import AddressBean;
 
PNS Subramanian
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edmund,

Try placing AddressBean inside a package for instance WEB-INF\classes\com\bean\AddressBean.class.
 
Edmund Yong
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

It is very strange, for the following two reasons:

(1) It works if I have package for the AddressBean class. If I don't have package like my original code, there will be compilation error.

(2) The following will not work. Tomcat complains that "The value for the useBean class attribute AddressBean is invalid."

<%@ page import="com.model.* " %>

<html>
<body>
<jsp:useBean id="address" class="AddressBean" scope="session" />
</body>
</html>

If I change the class attribute of <jsp:useBean> to "com.model.AddressBean", then it will compile without problems. It seems that the import is ignored.
 
David Bridgewater
author
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edmund...

JDK 1.4 doesn't support the default package any more, and the JSP spec has come out in sympathy with this.

Take a look at JSP 11.2.

Best,

David.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic