wood burning stoves 2.0*
The moose likes Servlets and the fly likes Passing web.xml info to servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Passing web.xml info to servlets" Watch "Passing web.xml info to servlets" New topic

Passing web.xml info to servlets

Caroline Harris

Joined: Jan 10, 2002
Posts: 3
Help i'm stuck....trying to send information from web.xml to MyBasket.java servlet to SimpleShoppingBasket servlet. The information from the web.xml file is passed successfully to the first servlet, but all information (apart from quantities) are listed as 0 or null when trying to send to the second servlet.
I'm new to servlets so dont really have a clue what i'm doing!!! Could anyone help? I have included my code if anyone fancies giving me a few tips!!
[ January 15, 2002: Message edited by: Mike Curwen ]
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Hi Caroline, welcome to the Ranch.

I've edited your post to include the UBB [ code ] tags.

Here's what I came up with. First, I've modified your web.xml a little bit:

Then, your first servlet is modified thus: Then, your second servlet...
As for what you are doing in the second servlet, you are attempting to retrive from the request, the values that you had placed into your table in the first servlet. But these values are not IN the request. They are only 'plain HTML' as output by that first servlet.

If you want to retrieve the name and quantity and price, these need to be made form fields as well, so that when you POST to the second servlet, they are placed in the request as well.

I could also get into the whole discussion about architecture, databases and how init-parameters aren't the best way to be doing what you are doing... but thought I'd just answer your question.

You need to make everything you want to retrieve from the request (in your second servlet) a parameter on the FORM in the first page.
[ January 15, 2002: Message edited by: Mike Curwen ]
Caroline Harris

Joined: Jan 10, 2002
Posts: 3
Thanks for the suggestions.....tried the 'hidden' types, but still didnt work!!
I must be doing something wrong! Do u have any other suggestions or links that might help me understand more?
Caroline Harris

Joined: Jan 10, 2002
Posts: 3
Hi Mike...i read through my code again and i'd made a boo boo!! Typo!
Your suggestion did work. Thank you very much!
It is sorta covered in the JavaRanch Style Guide.
subject: Passing web.xml info to servlets
Similar Threads
Connection Pooling
Forms in servlet
passing init-param to servlets from web.xml
Servlet Initialization Parameters
javax. servlet.Servlet Exception: Initialization failed, Unable to get DB connection