not able to access parameters  stored in web.xml from a servlet

Posted on 2006-04-30
Medium Priority
Last Modified: 2013-11-24
I am using tomcat 5.0  I AM NOT ABLE TO READ THE PARAMETERS in web.xml.
 the code is given below

package coreservlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ShowMessage extends HttpServlet {
private String message;
private String defaultMessage = "No message";
private int repeats = 1;
public void init(ServletConfig config)
throws ServletException {
// Always call super.init
message = config.getInitParameter("message");
if (message == null) {
message = defaultMessage;
try {
String repeatString = config.getInitParameter("repeats");
repeats = Integer.parseInt(repeatString);
} catch(NumberFormatException nfe) {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
String title = "The ShowMessage Servlet";
out.println(ServerUtilities.headWithTitle(title) +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1 ALIGN=CENTER>" + title + "</H1>");
for(int i=0; i<repeats; i++) {
      out.println(message + "<BR>");

The Web.xml file
<web-app >

The output I get is
The ShowMessage Servlet
No message
Please Help
Question by:cakurien

Expert Comment

ID: 16575953
check if the deployed servlet has the right version of the web.xml..
there does not seem to be any reason y this shouldn work..

Expert Comment

ID: 16575963
also check which version of the servlet API is supported by tomcat 5.0, and ensure the right DTD is reffered to in the web.xml
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 16576072
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 30

Expert Comment

by:Mayank S
ID: 16576405
BTW, does: >> repeats = Integer.parseInt(repeatString);

throw any exceptions? Is repeatString also not coming properly?

Author Comment

ID: 16584398
I got the ans I had to add the package name.class in <servlet-mapping> tag
LVL 30

Accepted Solution

Mayank S earned 1500 total points
ID: 16584851
You already had coreservlets.ShowMessage in the <servlet-class> so the package-name was there?

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month17 days, 12 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question