Wednesday, May 28, 2008

Java Tricky Question - 5

Q: How can you associate an array of values for an initialization parameter of a servlet?

A: You can’t; at least not directly! The deployment descriptor does not
allow you to specify multiple parameters with the same name. So you
have to do something like this:
< init-param >
< param-name > param1 < / param-name >
< param-value > val1 , val2 , val3 , val4 < / param-value >
< init-param >
You would then have to parse the param-value string in the servlet
and interpret the multiple values listed in the string.

No comments: