• 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

Head First Testing Init Paramters

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everyone,

I'm trying to create the example that tests requesting init paramters on p.154 of the Head First Servlets and JSP book. This example isn't a full tutorial, but I wanted to see if I can make it work.

I can load the first form page in my browser, but when I click on the submit button, I receive this error:



So it's looking like Tomcat can't find the TestInitParams servlet?

Here's my DD web.xml:



Here's the html for the initial form page:



And here's the code for the servlet:


The form.html file is in the directory c:\\tomcat\webapps\ch5
The DD web.xml file is in c:\\tomcat\webapps\ch5\WEB-INF
And the TestInitParams.class servlet is in c:\\tomcat\webapps\ch5\WEB-INF\classes\com\example\web

Any ideas why it can't find the servlet?

Thanks!
Matt
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Remove the > after "/Tester.do".
 
Matthew Busse
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!!!

But now I'm getting a different error when I click the submit button on the webpage:



So it seems like the servlet is throwing an exception to Tomcat? Is that caused by a problem in the servlet code, in the DD, or in the html?

Thanks again, I really appreciate the help!
Matt
 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Check the fully qualified class name you've specified in the web.xml. Does that match with the actual one ?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The TestInitParams servlet is in the com.example package, so you should have

instead of

 
Vishwanath Krishnamurthi
Ranch Hand
Posts: 331
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Matt,

Matthew Busse wrote:

And the TestInitParams.class servlet is in c:\\tomcat\webapps\ch5\WEB-INF\classes\com\example\web

Matt



In this case, you can only change the source code



to



and re-compile it.

You can leave the web.xml to be as
then.


HTH,
Vishwa
 
Matthew Busse
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had already tried changing the servlet-class in the DD to com.example.TestInitParams, and received this error:


I thought the file path had to be fully spelled out? In some earlier, similar examples, I had to include the .web.
 
Matthew Busse
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vishwanath Krishnamurthi wrote:Hi Matt,

In this case, you can only change the source code



to



and re-compile it.

You can leave the web.xml to be as
then.

HTH,
Vishwa



Thanks! This worked. I guess I need to go back and re-read the chapter on packages in the Java book. I thought I understood it, but apparently I don't...

Matt
 
There’s no place like 127.0.0.1. But I'll always remember this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic