aspose file tools*
The moose likes Servlets and the fly likes Head First Testing Init Paramters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Head First Testing Init Paramters" Watch "Head First Testing Init Paramters" New topic
Author

Head First Testing Init Paramters

Matthew Busse
Ranch Hand

Joined: Sep 29, 2010
Posts: 52
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

Joined: Nov 24, 2005
Posts: 14687
    
  16


Remove the > after "/Tester.do".


[My Blog]
All roads lead to JavaRanch
Matthew Busse
Ranch Hand

Joined: Sep 29, 2010
Posts: 52
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

Joined: Jun 04, 2007
Posts: 331
Hi,

Check the fully qualified class name you've specified in the web.xml. Does that match with the actual one ?


Blog
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

The TestInitParams servlet is in the com.example package, so you should have

instead of

Vishwanath Krishnamurthi
Ranch Hand

Joined: Jun 04, 2007
Posts: 331
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

Joined: Sep 29, 2010
Posts: 52
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

Joined: Sep 29, 2010
Posts: 52
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Head First Testing Init Paramters