• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Newbie problem from chapter1 of Head First Servlets & JSP

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm reading Head First Servlets & JSP.

In Chapter1 there's a small example but I canĂ½ get it work.

I wrote this class



Which I compiled without problems.

I wrote this DD:



This is where the files are on my PC:

C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ch1\WEB-INF\web.xml
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ch1\WEB-INF\classes\Ch1Servlet.class


I try to access it using:

http://localhost:8080/ch1/Serv1/

But Tomcat gives my an error 404.

What am I doing wrong?

Thanks a lot!
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Step 1: Put the servlet in a class other than the default

Step 2: If it works, profit! If not, post back.
 
Carlos Obregon
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry but I don't understand what do you mean by "default"!
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basic Java: the default package is used when you don't specify a package.

As of Java 1.4, the default package is not automatically included. Bottom line: place all of your classes in an explicit package.

Please see this FAQ entry.
 
Carlos Obregon
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. Thanks! I used other package but it still doesn't work:

My Servlet class is:



My web.xml file is:



The files are in:

C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ch1\WEB-INF\classes\com\examples\Ch1Servlet.class
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ch1\WEB-INF\web.xml

Thank you a lot!
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, that's been eliminated as a possible source of error.

Now, saying "it doesn't work" isn't all that helpful. Please read this for more information.

What is the URL you are using, and what is the exact text of the error message?
 
Carlos Obregon
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The URL I'm using is:

http://localhost:8080/ch1/Serv1/

Its a 404 error it says "required resource is not available"

 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you restarted the ch1 context/tomcat server after placing the servlet class in the right place ? (Or when you put the changed web.xml there context will get restarted automatically).
 
Carlos Obregon
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure I'm following.

Everytime I tried something I shutdown Tomcat first, the I restarted. Is there anything else to do to restart the context/Tomcat?

I did not understand what you said about the web.xml file

As I come to understand the thing is:

Everything that Tomcat will use must be in the directory "webapps"

Inside that directory there must be a directory per app.

Inside each app root directory there must be a WEB-INF directory. Inside it there must be a "classes" directory and under it there must be directories that matches the packages you are using.

Static context that you intent your client to use must be in the root or a directory structure not under WEB-INF.

The web.xml must be in the app root directory.

Right? Is that so for every Tomcat version or it may have changed?

Thanks a lot.
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I assume you have mistyped closing tag in line
<url-pattern>/Serv1</servlet-class>
?

What does your tomcat error log say?



[quote=Carlos Obregon]I'm not sure I'm following.

Everytime I tried something I shutdown Tomcat first, the I restarted. Is there anything else to do to restart the context/Tomcat?

I did not understand what you said about the web.xml file

As I come to understand the thing is:

Everything that Tomcat will use must be in the directory "webapps"

Inside that directory there must be a directory per app.

Inside each app root directory there must be a WEB-INF directory. Inside it there must be a "classes" directory and under it there must be directories that matches the packages you are using.

Static context that you intent your client to use must be in the root or a directory structure not under WEB-INF.

The web.xml must be in the app root directory.

Right? Is that so for every Tomcat version or it may have changed?

Thanks a lot.[/quote]
 
Carlos Obregon
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah! You are right it's a mistype I needed to type as the url http://localhost:8080/ch1/Serv1

Thanks.
 
Those cherries would go best on cherry cheesecake. Don't put those cherries on this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic