• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple config parameters within init-param

 
Aniket Patil
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's funny you don't get a parse error, because only one param-name and param-value is allowed per init-param.
 
Aniket Patil
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found it, thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic