aspose file tools*
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
Author

initialization parameters

Anonymous
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"
"http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">
<web-app>
<servlet>
<servlet-name>
initParameter
</servlet-name>
<servlet-class>
initPara
</servlet-class>
<init-param>
<param-name>initial</param-name>
<param-value>matt</param-value>
</init-param>
</servlet>

</web-app>
here is the servlet file:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

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

Joined: Mar 22, 2000
Posts: 12806
    
    5
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.
Bill
 
Don't get me started about those stupid light bulbs.
 
subject: initialization parameters