• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

404/resourse not availabel elicpse-tomcat

 
Benjamin Madore
Greenhorn
Posts: 11
Tomcat Server Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to follow the tutorials is the O'Rielly Java Servlet Programming book, but I can't get the example to work. I put a jsp in web-inf and it appeared. (Tomcat 7.0.53)

The servlet:


The web.xml:


I've tried removing "servlet" from the path, but I still get the 404 "The requested resource is not available."

I imagine it's something obvious, but there's a bit of a gap in the book I have and what I'm running on.

I can get a jsp page to show, so I'm relatively certain I have everything correct. I just press the "run" button and select Tomcat.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's WEB-INF, not web-inf.

And why have you mapped /* to your servlet?
 
Benjamin Madore
Greenhorn
Posts: 11
Tomcat Server Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:It's WEB-INF, not web-inf.

And why have you mapped /* to your servlet?


Sorry, yes, capitalization matters in some places.

I mapped /* in an effort to get any response from the servlet.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remove the mapping as it'll cause more problems than sole any.

Have you gone through the steps in the ServletsFaq?
 
Benjamin Madore
Greenhorn
Posts: 11
Tomcat Server Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Benjamin Madore
Greenhorn
Posts: 11
Tomcat Server Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to figure this out, to get my "hello world" example going with the intention of teaching myself. I have added "package test;" to my source and tried changing my web.xml to:


I created a directory and now the source is at: src/test/init.java

I'm seeing init.class under build/classes/test

when I go to http://localhost:8080/InitDestoryCounter/init I'm still getting "The requested resource is not available"
 
Benjamin Madore
Greenhorn
Posts: 11
Tomcat Server Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also tried importing a pre-made project from http://www.coreservlets.com/Apache-Tomcat-Tutorial/tomcat-7-with-eclipse.html in "test-app.zip" and I get the same error.

I tried cleaning, deleting and rebooting things... I think it worked.
 
J. Kevin Robbins
Bartender
Posts: 1725
19
Chrome Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Benjamin Madore wrote:


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.
 
Benjamin Madore
Greenhorn
Posts: 11
Tomcat Server Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic