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

initialization parameters

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi All
I'm trying to set initial value in a sevlet.
i'm using tomcat3.1,or jsdk2.
with Tomcat you have to create an xml file and set the name of the servlet and the name and the value of the parameter.
but there is a default web.xml file in web-inf.
do i have to just put a name for a file with extension xml and put it along with the default file(web.xml?
or i have to move that default file(web.xml) and put it somewhere and name my file web.xml and put it at that directory(web-inf).
really i do not know and that what i did,but i got just null.
that means something wrong and the that parameter doesn't exist.
here is the files:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"

here is the servlet file:
import javax.servlet.*;
import javax.servlet.http.*;

public class initPara extends HttpServlet
private String initial;
public void init(ServletConfig config) throws ServletException
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
PrintWriter out=res.getWriter();
here is my url: http://localhost:8080/examples/servlet/initParameter
thanks for your help.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
The default web.xml should work for experimentation. As I understand it you only use the application specific web.xml files to specify parameters for those applications that may override the default. Double-check the spelling and the use of upper/lower case in your servlet name and class name.
I agree. Here's the link:
subject: initialization parameters
It's not a secret anymore!