This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

what's wrong with my basic test servlet?

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am new to servlet, and have a basic question regarding to it. I am struggle of making it work in Eclipse Luna. It always gave me an


Eventhough I have define my servlet in the /src/org/dung/TestServlet in the servlet file structure attachment. So I don't know why it could not find it and complain.

Also my basic TestServlet is as follow:


and the web.xml is defined as follow:



So if you spot something wrong or missing, please let me know.

Thank you so much!


servlet.png
[Thumbnail for servlet.png]
Servlet file structure
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Eventhough I have define my servlet in the /src/org/dung/TestServlet in the servlet file structure attachment.



The servlet container is looking for a compiled class file, it does not care about where your source is.

Another example of why I suggest beginners should NOT start with an IDE like Eclipse, it hides stuff from you and does things behind your back.

The servlets FAQ here at the ranch is a resource you need to get familiar with.

Bill
 
Marshal
Posts: 67430
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where the source file goes is irrelevant. It's where the class file ends up that's important. Are you using an IDE? I suspect who from your screen shot.

Also, you might want to rethink your package name. Do you know what dung means in English?
 
tom mi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Bear,

Thank you for your response.In term of IDE , I use Eclipse Luna. I followed the instruction from the tutorial and I have no idea why it is complaining that it could not find my file eventhough my file is defined under src/my package name/ java class. One thing that i am not sure of even though I compiled and clean my java file in eclipse Luna, it does not produce a class file in web-inf/lib. I don't know if it is hidden so i could not find it, or I will see it when I deploy the app to WAR file. In any case, I run my program from Eclipse Luna and I would like to see it running there before I deploy the WAR.

Tommidu
 
Bear Bibeault
Marshal
Posts: 67430
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The class files should end up in a hierarchy under WEB-INF/classes
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

tom mi wrote:

One thing that i am not sure of even though I compiled and clean my java file in eclipse Luna, it does not produce a class file in web-inf/lib..



Please check the Properties of your project in eclipse. There is an option to override the directory where your compiled classes go. As I go with everyone, using IDEs is *NEVER* a good companion for beginners, as that masks out several things which definitely will NOT help the beginners. I suppose Eclipse Luna offers the default directory for storing the compiled classes as "build\classes". Instead it should be "WEB-INF\classes". After your reset this property, refresh the project and do build the project again. (You can better do a Clean compile).

Note: Beware of the case (lowercase, uppercase) of the directory structure as Java is a case-sensitive language. This directory should strictly be WEB-INF. It should NOT be any of Web-INF, web-inf, WEB-Inf etc.,
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic