Dear All Tomcat Users,
I'm working on upgrading Tomcat from a very old version to 4.1.x
Currently, we have a servlet being run at the start of the web (specified in
web.xml ).
But this servlet may have some objects obsoleted in ver 4.1.x.
Does anyone know how should I change this servlet in order to make it runs
on Tomcat 4.1.x?
THANKS IN ADVANCE!!!!!!
Here is the code:
package com.xxx.common;
.
import ....
import ....
import ....
....
...
..
.
import java.util.Hashtable;
import java.util.Properties;
import java.io.File;
import java.io.IOException;
import javax.mail.Session;
import javax.servlet.GenericServlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.ServletException;
import org.apache.tomcat.core.Context;
import org.apache.tomcat.core.ServletContextFacade;
/**
* InitServlet is a "faceless" servlet that is automatically started when
* the servlet container starts. InitServlet requires only one initial
parameter
* at startup: config. This parameter refers to the property that will
contain
* all the tunables for the site.
*
* ...
* ...
*/
public class InitServlet extends GenericServlet {
private static Hashtable obj_table;
private static String CONFIG_NAME = "xxx.properties";
public InitServlet() {
super();
}
/**
* Initialization routine to startup services for xxx
*
* @param conf configuration for this servlet
* @exception ServletException not used in this method
*/
public void init(ServletConfig conf) throws ServletException {
super.init(conf);
obj_table = new Hashtable();
// Get the context of this servlet
Context context = ((ServletContextFacade) conf.getServletContext()).
getRealContext();
obj_table.put(context.getClass().getName(), context);
String conf_filename = context.getContextManager().getTomcatHome() +
File.separator + "conf" + File.separator + CONFIG_NAME;
if (! new File(conf_filename).exists()) {
// Configuration file doesn't exist; tell user
log("Configuration file: " + conf_filename + " does not
exist");
log("Please make sure file exist for the iSteelAsia.com
application");
System.err.println("Configuration file: " + conf_filename +
" does not exist");
System.err.println("Please make sure file exist for the
iSteelAsia.com application");
return;
}
....
....
...
..
.
}
/**
* Retrieves an object out of the object hash table.
*
* @param name the given name of the object
* @return the actual object
*/
public static Object getObject(String name) {
if (obj_table == null) {
return null;
}
return obj_table.get(name);
}
/**
* Inserts an object into the object hash table.
*
* @param name the name of the object
* @param key the object itself
*/
public static void setObject(String name, Object key) {
if (obj_table == null) {
return;
}
obj_table.put(name, key);
}
/**
* The service method is blank, meaning that this servlet will do nothing
other then
* a faceless init. This servlet will return no data.
*
* @param request javax.servlet.ServletRequest servlet request object
* @param response javax.servlet.ServletResponse sevlet response object
*/
public void service(ServletRequest request, ServletResponse response)
throws ServletException, IOException { }
} /* InitServlet */