This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Building Blockchain Apps and have Michael Yuan on-line!
See this thread for details.
Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Head First Testing Init Paramters

 
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
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • 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
 
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 VI Editor Ubuntu
  • 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
 
Why am I so drawn to cherry pie? I can't seem to stop. Save me tiny ad!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!