Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Servlets and the fly likes problem with web.xml and the getinitParameter() func Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "problem with web.xml and the getinitParameter() func" Watch "problem with web.xml and the getinitParameter() func" New topic

problem with web.xml and the getinitParameter() func

Preetham Chandrasekhar
Ranch Hand

Joined: Nov 05, 2003
Posts: 98
hi all,
I have my code below and Im not sure for what reason it isnt working! I did change my web.xml in the WEB-INF directory as well to contain the servlet name and the init-param and its corresponding values. However when
I try running the gives the 404 error.
I have the code and the web.xml extract below...
package coreserv;
import javax.servlet.*;
import javax.servlet.http.*;
public class InitParams extends HttpServlet implements SingleThreadModel{
private String message;
boolean debug;
private int repeats = 1;
private String defaultMessage = "No Message";
public void init() throws ServletException{
message = getInitParameter("message");
message = defaultMessage;
String repeatString = getInitParameter("repeats");
repeats = Integer.parseInt(repeatString);
}catch(NumberFormatException nfe){


public void toGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
PrintWriter out = response.getWriter();
String title = "The Message shown:";

out.println(ServletUtilities.HeadWithTitle(title) + "<BODY><H1>" + title + "</H1>");
for(int i=0;i<repeats;i++){
out.println(message + "<BR>");



//web.xml...from /examples/WEB-INF/web.xml

and I type in
both dont work..... :-(
I also tried this in init(ServletConfig config){} method as well...but no luck!!!
any suggestions?
any suggesstions....

"In theory, there is no difference between theory and practice. But, in practice, there is."<br /> - Jan L.A. van de Snepscheut
Juanjo Bazan
Ranch Hand

Joined: Feb 04, 2002
Posts: 231
Using the /servlet/ pattern means you want to use the invoker servlet which probably is disabled by default in your server(check the web.xml of the server's configuration).
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13028
See the ranch FAQ entry on the invoker.
VermaJitendra Verma

Joined: Apr 15, 2004
Posts: 2
Hello there
let us know if the exmaple u are running is on WIN or Linux.
If it is linux then check your rights on the particular fiel. It happened to me in linux.
Preetham Chandrasekhar
Ranch Hand

Joined: Nov 05, 2003
Posts: 98
this is what is in my conf/web.xml invoker servlet and it is not commented....but still it isnt wrking...and this is being done on windows(sadly).
Preetham Chandrasekhar
Ranch Hand

Joined: Nov 05, 2003
Posts: 98
hi guys,
got it was so stupid...instead of doGet() in the above code i put in toGet()..... wasted hours figuring out this...sorry to take ur time as well....
I agree. Here's the link:
subject: problem with web.xml and the getinitParameter() func
It's not a secret anymore!