File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes problem reading the initialization parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "problem reading the initialization parameters" Watch "problem reading the initialization parameters" New topic

problem reading the initialization parameters

trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 614
I have a servlet which reads the initialization parameter & displays it.If there is no initialization parameter it displays the default message.
but in my case even though there is an initialization parameter defined in the web.xml my servlet is displaying the default message.
what can be the error??
I store the .java files under myServlet directory which is set in the classpath.All the .class files are saved under install-dir/webapps/root/WEB-INF/classes directory.

below is the servlet code..

import javax.servlet.*;
import javax.servlet.http.*;
public class ShowMessage extends HttpServlet
private String message;
private String defaultMessage = "no message";
private int repeats = 1;

public void init(ServletConfig config) throws ServletException

message = config.getInitParameter("message");

message = defaultMessage;
String repeatString = config.getInitParameter("repeats");
repeats = Integer.parseInt(repeatString);
catch(NumberFormatException nfe)

public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException
PrintWriter out = response.getWriter();
String title = "The ShowMessage Servlet";
"<body bgcolor = \" #FDF5E6\">\n"+
"<H1 align=center>"+ title +"</H1>");

for(int i=0;i<repeats;i++)
out.println(message + "<br>");


}//--end of class
below is the web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

<param-value>Hello there</param-value>
thanks in advnce..
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
try ,
i'm not sure but when u call super.init() and if its emptying the config object...
i'll try to do something like this tommorrow and 'll let u know..
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
i meant- getServletConfig().getInitParameter()...
I agree. Here's the link:
subject: problem reading the initialization parameters
It's not a secret anymore!