You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Dominik Jednoralski <to...@lime-design.de> on 2002/02/07 19:02:13 UTC
Newbie problem with reading init params
Hey Guys,
I have a problem with getting my init-params from the web.xml-file.
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
. Lime Design Mediengestaltung
. Lilienstr. 23
. 63768 Hvsbach
. Tel. 06021.550470
. visit www.lime-design.de
--
To unsubscribe: <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>