On Thu, 3 Jan 2002, Chen, Gin wrote: > I had the same issue.. I cant find anything in the APIs that offer > support for multiple values for the same param in the init params > methods. I had to use a second XML file and use a XSL file to load > it in as an array. The approach of using an XSL is so that I can use > the array in javascript only. If you want to be able to use the > values in Server side code, you have to write a simple XML parser.
Another possibility is to define the param (in web.xml) as a comma-separated value (csv) and parse it when you get it. For example: <init-param> <param-name>team</param-name> <param-value>GoodGuys,Enemy</param-value> </init-param> Then: ... String teamNameCSV = config.getInitParameter("appName"); String[] teamNames = StringUtils.splitCSV(teamNameCSV); ... (StringUtils is my own class; it contains mostly static functions, including ones to do this parsing.) Parsing a comma-delimited string (or with some other delimiter, like colon) into an array of strings is something I've found useful, so I already have classes/methods to do that. (But then I do a lot of perl, where split is so easy and natural :-). And I'm sure there are other Java string-manipulation packages out there that have simile methods. Note: I haven't actually tried this, I assume there are no gotchas, like that commas aren't allowed in param values. > -----Original Message----- > From: Gerry Scheetz [mailto:[EMAIL PROTECTED]] > Sent: Thursday, January 03, 2002 1:00 PM > To: [EMAIL PROTECTED] > Subject: loading array of data from InitParameter > > > I am trying to keep from having to constantly edit and recompiling my > servlet class. To do this I would like to move the information that is > stored in an array to the applications web.xml file and loaded in the init > method rather than hard coding the creation of the array. > > The web.xml file would look like this: > <init-param> > <param-name>team</param-name> > <param-value>GoodGuys</param-value> > </init-param> > <init-param> > <param-name>team</param-name> > <param-value>Enemy</param-value> > </init-param> > > The following is how I usually load the information from the web.xml file. > ServletConfig config = getServletConfig(); > String teamName = config.getInitParameter("appName"); > > But do not know how to load the information into an array of String objects. Milt Epstein Research Programmer Software/Systems Development Group Computing and Communications Services Office (CCSO) University of Illinois at Urbana-Champaign (UIUC) [EMAIL PROTECTED] ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html