Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet and Xml

 
David Li
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, Bill, how can I solve this problem?
 
David Li
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic