This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Import class not working for Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Import class not working for Servlet" Watch "Import class not working for Servlet" New topic
Author

Import class not working for Servlet

Mike Jenkins
Ranch Hand

Joined: Jul 23, 2006
Posts: 57
I am trying to get my first import to work in Tomcat 5.5 container but it is giving me error.

Here is my Controller:


Here is my bean file:


My JSP called Third.jsp:


I mapped in the web.xml so it should show on the web as:
http://127.0.0.1:8080/test/First

My error:

java.lang.NoClassDefFoundError: First (wrong name: beans/First)



My First.java is located in Tomcat 5.5 Home\webapps\test\WEB-INF\classes and the bean is located in Tomcat 5.5 Home\webapps\test\WEB-INF\classes\beans. My jsp is located in C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\test


Please advise.
[ July 23, 2006: Message edited by: Mike Jenkins ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60798
    
  65

Your import is not valid. You cannot import a package, you must import classes.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mike Jenkins
Ranch Hand

Joined: Jul 23, 2006
Posts: 57
Please advise how I do that?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60798
    
  65

Same way as for Java classes.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You need to either list each class explicitly:


or, to import all beans in a package, you can use the wildcard (*):


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Mike Jenkins
Ranch Hand

Joined: Jul 23, 2006
Posts: 57
Thanks to both of you.
It now works.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Import class not working for Servlet
 
Similar Threads
Servlet delivery in Tomcat
Tomcat 404 error
getting error while running servlet in tomcat
Configuring JNDI for JavaBean in Tomcat 5
servlet not reloading on Tomcat 4.0