• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Head First Testing Init Paramters

 
Matthew Busse
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • 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
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Remove the > after "/Tester.do".
 
Matthew Busse
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • 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
 
Vishwanath Krishnamurthi
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • 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 Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic