File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Multiple config parameters within init-param Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Multiple config parameters within init-param" Watch "Multiple config parameters within init-param" New topic
Author

Multiple config parameters within init-param

Aniket Patil
Ranch Hand

Joined: May 02, 2006
Posts: 218
I have a mock Beer-recommendations web app, with a servlet that accesses the init-parameters (servlet config parameters) from the DD, sets them as attributes and forwards the request to a JSP. The JSP retrieves the attributes and prints them to the response stream.


The entire set up works fine and along with the Beer Recommendations, i get the output as
This application has been created by Aniket Patil.

The problem: Instead of having 2 separate <init-param>, i tried to club together both the params i.e. name and lastName into one init-param, as in:

However, now i am only able to access the second param, lastName correctly. If the order of declaration of the params within <init-param> is reversed (i.e. lastName comes first, then name), i am able to access only "name" value correctly i.e. the output is one of

This application has been created by Aniket null.
OR
This application has been created by null Patil.

Can there be only a single init parameter declared within <init-param> at a time, and for multiple declarations, can it access only the last one correctly?
[ January 17, 2007: Message edited by: Aniket Patil ]

SCJP 5.0 | SCWCD 1.4 <br /> <br />If you don't know where you are going, any road will take you there!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

It's funny you don't get a parse error, because only one param-name and param-value is allowed per init-param.


[My Blog]
All roads lead to JavaRanch
Aniket Patil
Ranch Hand

Joined: May 02, 2006
Posts: 218
Satou,

Using Tomcat 5.x, which from my observations reads the DD at server startup, and no parse error is seen then.

Is it mentioned in the spec that only a single param is allowed per init-param? I myself havent been through the spec yet, so would be good if you could post the exact statement from spec to settle the issue for good.
[ January 17, 2007: Message edited by: Aniket Patil ]
Suchen Chodankar
Ranch Hand

Joined: Sep 18, 2006
Posts: 47
Hi,
Yes. When you want to define multiple parameters in a single servlet you have to do it the way as shown below.



And the same rule applies when it comes to <context-param> also.

That is when you want to define multiple context parameters you should not put all of then in a single <context-param>.

Rather you need to have different <context-param> block for different context paramater.
Aniket Patil
Ranch Hand

Joined: May 02, 2006
Posts: 218
Suchen,

Its pretty apparent, inserting multiple params in a single ,<init-param> doesen't work correctly.

Have you come across any documentation(perhaps the Servlet specification), that mentions this?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Is it mentioned in the spec that only a single param is allowed per init-param?


Yes it is.
SRV.13.4 Deployment Descriptor Diagram
Aniket Patil
Ranch Hand

Joined: May 02, 2006
Posts: 218
Found it, thanks!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Multiple config parameters within init-param
 
Similar Threads
Clarification in the order in which the DD is read by the container!!
getInitParameter
JSTL not working on tomcat 4.1.18
HTTP Status 404 Error
What is the need for ServletConfig