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

Posted on 2006-04-30
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 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
    LVL 3

    Expert Comment

    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..
    LVL 3

    Expert Comment

    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

    LVL 30

    Expert Comment

    BTW, does: >> repeats = Integer.parseInt(repeatString);

    throw any exceptions? Is repeatString also not coming properly?

    Author Comment

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

    Accepted Solution

    You already had coreservlets.ShowMessage in the <servlet-class> so the package-name was there?

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
    Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
    Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
    The viewer will learn how to implement Singleton Design Pattern in Java.

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now