wood burning stoves 2.0*
The moose likes Servlets and the fly likes Servlet and Xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet and Xml" Watch "Servlet and Xml" New topic
Author

Servlet and Xml

David Li
Greenhorn

Joined: Nov 23, 2000
Posts: 16
I was trying to read the initial prmameters saved in web.xml through a servlet. The server I am using is Tomcat3.1. I couldn't get any of the parmameters. The program is from "Core Servlets and JavaServer Pages". Here is the program:
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) {}
}
And here is the xml file with the message or parameters:
<?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>
ShowMsg
</servlet-name>
<servlet-class>
learnServlet.ShowMessage
</servlet-class>
<init-param>
<param-name>message</param-name>
<param-value>Shibboleth</param-value>
</init-param>
<init-param>
<param-name>repeats</param-name>
<param-value>5</param-value>
</init-param>
</servlet>
</web-app>
Thank any one for your inputs.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
You might try running through the enumeration of init-params that are being passed to this servlet
Enumeration e = config.getInitParameterNames();
so you can see if anything is getting through.
Bill
Vladan Radovanovic
Ranch Hand

Joined: Mar 20, 2000
Posts: 216
Are You invoking the servlet with http://localhost/servlet/ShowMsg or http://localhost/servlet/learnServlet.ShowMessage ?
It should be the first one.
David Li
Greenhorn

Joined: Nov 23, 2000
Posts: 16
Originally posted by William Brogden:
You might try running through the enumeration of init-params that are being passed to this servlet
Enumeration e = config.getInitParameterNames();
so you can see if anything is getting through.
Bill

I think that's the problem, the init-params were not passed to this servlet, since I could only get the default message.
David Li
Greenhorn

Joined: Nov 23, 2000
Posts: 16
So, Bill, how can I solve this problem?
David Li
Greenhorn

Joined: Nov 23, 2000
Posts: 16
Originally posted by Vladan Radovanovic:
Are You invoking the servlet with http://localhost/servlet/ShowMsg or http://localhost/servlet/learnServlet.ShowMessage ?
It should be the first one.

You are right. Thank you and Bill.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet and Xml