You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Les Dunaway <le...@glsi.us> on 2003/12/17 22:42:59 UTC

Problem with initialize servlet - load-on-startup

I'm running Tomcat 406 on Redhat9

I have a working Struts app

I've added a second servlet to web.xml, specifying load-on-startup 2
(where 1 is Action servlet

The second servlet is ignored (or at least it doesn't produce anything
in the logs) - the log shows the parsing of the web.xml going normally
(no errors).

Can anyone tell me what I didn't do / did wrong?

Les
+++++++++++++ web.xml +++++++++++++++++++++++
<?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>

  <!-- Standard Action Servlet Configuration (with debugging) -->
  <servlet>
    <servlet-name>action</servlet-name>
   
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
      <param-name>debug</param-name>
      <param-value>3</param-value>
    </init-param>
    <init-param>
      <param-name>detail</param-name>
      <param-value>2</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  
<!-- Initialization servlet -->
    <servlet>
        <servlet-name>glsi-init</servlet-name>
       
<servlet-class>com.glsi.share.ApplicationInitialze</servlet-class>
        <init-param>
            <param-name>glsi-config</param-name>
           
<param-value>/WEB-INF/classes/glsi-config.properties</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>

  <!-- Standard Action Servlet Mapping -->
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  
  <!-- The Usual Welcome File List -->
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>


  <!-- Struts Tag Library Descriptors -->
  <taglib>
    <taglib-uri>/tags/struts-bean</taglib-uri>
    <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
  </taglib>

  <taglib>
    <taglib-uri>/tags/struts-html</taglib-uri>
    <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
  </taglib>

  <taglib>
    <taglib-uri>/tags/struts-logic</taglib-uri>
    <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
  </taglib>

  <taglib>
    <taglib-uri>/tags/struts-nested</taglib-uri>
    <taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
  </taglib>

  <taglib>
    <taglib-uri>/tags/struts-tiles</taglib-uri>
    <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
  </taglib>

</web-app>


+++++++++++++++++++++ The servlet ++++++++++++++++++++++++
/*
 * ApplicationInitialize.java
 *
 * Created on December 15, 2003, 12:36 PM
 */

package com.glsi.share;

import java.io.*;
import java.net.*;

import java.util.Properties;

import javax.servlet.*;
import javax.servlet.http.*;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Performs initialization for glsi class-libraries-based applications
 * @author  Les
 * @version
 */
public class ApplicationInitialize extends HttpServlet {
  
  /**
   *  The <code>Log</code> instance for this application.
   */
  private Log log =
  LogFactory.getLog("com.glsi.share.ApplicationInitialize");
  
  /** Initializes the servlet.
   */
  public void init(ServletConfig config) throws ServletException {
    super.init(config);
    System.out.println(">>>>>>>>>>Hi there, I'm the
initializer<<<<<<<<<<<<<<<<");
    String cfgPathName = config.getInitParameter("config");
    Properties cfgProps = new Properties();
    try{
    cfgProps.load(new FileInputStream(cfgPathName));
    } catch (Exception ie) {
      log.info("Error loading glsi-config.properties" +
ie.getMessage());
    }
    log.info("glsi-config.properties loaded");    
  }
  
  /** Destroys the servlet.
   */
  public void destroy() {
    
  }
  
  /** Processes requests for both HTTP <code>GET</code> and
<code>POST</code> methods.
   * @param request servlet request
   * @param response servlet response
   */
  protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
  throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    /* output your page here
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet</title>");
        out.println("</head>");
        out.println("<body>");
     
        out.println("</body>");
        out.println("</html>");
     */
    out.close();
  }
  
  /** Handles the HTTP <code>GET</code> method.
   * @param request servlet request
   * @param response servlet response
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse
response)
  throws ServletException, IOException {
    processRequest(request, response);
  }
  
  /** Handles the HTTP <code>POST</code> method.
   * @param request servlet request
   * @param response servlet response
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse
response)
  throws ServletException, IOException {
    processRequest(request, response);
  }
  
  /** Returns a short description of the servlet.
   */
  public String getServletInfo() {
    return "Performs initialization for glsi class-libraries-based
applications";
  }
  
}




---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org