This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Ok, I'm looking at the FAQ. (I was previously maintaining older code, and I have come from a mostly php, C and C++ background.) This is my first from scratch servlet.
I think I don't have a package. I just ran the wizard in eclipse and put my code in it, and my .java file sits in the "src" folder and not a sub folder. It would have to sit in a sub folder and have a package keyword? The wizard didn't do that.
I would have to change all that and then point the web.xml file to something other than:
I would make it something like "IntDestroyCounter.<new package>.init" so the class and path match up as well. Then put a folder in for the new package, and put "package init" at the top of init.java.
In my opinion, letting a wizard generate your code isn't doing you any favors. Use the IDE as a smart editor, but write all the code yourself.
And yes, servlets, along with all other classes in a web app, must be in a package. But no, the InitDestroyCounter would not be part of the package. The package hierarchy would be rooted at src, and must be mirrored in WEB-INF/classes.
If you are not familiar with Java packages, that's a core concept you need to understand before writing web apps.
Don't do empty catch blocks. Ever. It's only a matter of time before that bites you in the butt. You'll find that even just printing the stacktrace will give you a clue that would help you track down the error, without which you'll spend hours scratching your head.
"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson