• 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

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: 67340
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: 67340
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.,
 
When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!