Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

what's wrong with my basic test servlet?

 
tom mi
Greenhorn
Posts: 8
  • 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
 
William Brogden
Author and all-around good cowpoke
Rancher
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
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65535
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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: 8
  • 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
Author and ninkuma
Marshal
Posts: 65535
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The class files should end up in a hierarchy under WEB-INF/classes
 
Raghavan Muthu
Ranch Hand
Posts: 3381
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.,
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!