1 Reply Latest reply on May 29, 2003 5:02 AM by Adrian Brock

    JBoss could not get my message from init()

    sabar Newbie


      pls tell me why when run my servlet, JBoss could not

      read my message in init()

      i made the following steps

      1- write my servlet

      package coreservlets;

      import java.io.*;
      import javax.servlet.*;
      import javax.servlet.http.*;
      /** Example using servlet initialization. Here, the message
      * to print and the number of times the message should be
      * repeated is taken from the init parameters.
      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) {
      // NumberFormatException handles case where repeatString
      // is null *and* case where it is something in an
      // illegal format. Either way, do nothing in catch,
      // as the previous value (1) for the repeats field will
      // remain valid because the Integer.parseInt throws
      // the exception *before* the value gets assigned
      // to repeats.
      public void doGet(HttpServletRequest request,
      HttpServletResponse response)
      throws ServletException, IOException {
      PrintWriter out = response.getWriter();
      String title = "The ShowMessage Servlet";
      out.println(ServletUtilities.headWithTitle(title) +
      "<BODY BGCOLOR=\"#FDF5E6\">n" +
      "<H1 ALIGN=CENTER>" + title + "</H1>");
      for(int i=0; i<repeats; i++) {
      out.println(message + "");

      2- web.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">


      This a description of my web app made by Eclipse

      <display-name>This is the display name of my J2EE component</display-name>
      This is the description of my J2EE component