i just use String thisString = getInitParameter("nameofparameter");
matt ----- Original Message ----- From: "Dominik Jednoralski" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Sunday, February 10, 2002 11:49 AM Subject: Error reading init-params > Hey Guys, > > I have a problem with getting my init-params from the web.xml-file. I'm > using > Tomcat 4, and these are the parameters I inserted into the > webapps/root/web-inf/web.xml-file: > > <web-app> > <servlet> > <servlet-name>ShowMsg</servlet-name> > <servlet-class>limeservlets.ShowMessage</servlet-class> > <init-param> > <param-name>message</param-name> > <param-value>Nerv-Serv</param-value> > </init-param> > <init-param> > <param-name>repeats</param-name> > <param-value>5</param-value> > </init-param> > </servlet> > </web-app> > > Now I failed to read these parameters with the follwing servlet: > > > package limeservlets; > > import javax.servlet.*; > import javax.servlet.http.*; > import java.io.*; > > public class ShowMessage extends HttpServlet { > private String message; > private String defaultMessage = "Leider keine Nachricht."; > private int repeats = 1; > > public void init (ServletConfig config) throws ServletException{ > super.init(config); > message = config.getInitParameter("message"); > if (message == null) { > message = defaultMessage; > } > > try { > String repeatString = config.getInitParameter ("repeats"); > repeats = Integer.parseInt(repeatString); > } catch (NumberFormatException nfe){} > } > > public void doGet (HttpServletRequest request, HttpServletResponse > response) > throws ServletException, IOException{ > response.setContentType("text/html"); > PrintWriter out = response.getWriter(); > String title = "The Servlet which shows a message!"; > > out.println(ServletUtilities.headWithTitle(title) + > "<body bgcolor=#fdf5f6>\n<h1>"+ title + "</h1><br>"); > for (int i = 0; i < repeats; i ++) { > out.println(message + "<br>"); > } > out.println("</body></html>"); > } > } > > > Does anyone know the reason for that? I for myself don't have a clue- I'm > not really into configuring servers... > > Dominik Jednoralski > > > -- > To unsubscribe: <mailto:[EMAIL PROTECTED]> > For additional commands: <mailto:[EMAIL PROTECTED]> > Troubles with the list: <mailto:[EMAIL PROTECTED]> > -- To unsubscribe: <mailto:[EMAIL PROTECTED]> For additional commands: <mailto:[EMAIL PROTECTED]> Troubles with the list: <mailto:[EMAIL PROTECTED]>