Hello!
I have some problems to read the init-parameters for my servlet.
I'm usign tomcat 3.2.3, mod-jk. But tested with tomcat standalone on
port 8080.
Here's my web.xml, located on TOMCAT_HOME/webapps/test/WEB-INF/
<web-app>
<servlet>
<servlet-name>remoteServlet</servlet-name>
<servlet-class>ch.hephaistos.web.RemoteServlet</servlet-class>
<init-param>
<param-name>server-host</param-name>
<param-value>localhost</param-value>
</init-param>
<init-param>
<param-name>server-name</param-name>
<param-value>ServletServer</param-value>
</init-param>
<init-param>
<param-name>timeout</param-name>
<param-value>80000</param-value>
</init-param>
<load-on-startup>5</load-on-startup>
</servlet>
</web-app>
if I don't include the <load-on-startup> tag the init-param will never
be read !
and here's a snippet of my servlet code:
public class RemoteServlet extends HttpServlet implements RRemoteServlet {
private String serverHost="localhost";
private String severName="ServletServer";
private RServletServer server;
private int timeout=60000;
private static int count=0;
private int number;
public void init(ServletConfig config) throws ServletException {
super.init(config);
processes = new Hashtable(5);
// config Log4J
String prefix =
this.getServletContext().getRealPath("/WEB-INF/conf/");
Log.loadConfig(prefix+"log4j.lcf");
Log.log.debug("Log4J configuration laoded");
// load configuration
serverHost = config.getInitParameter("server-host");
Log.web.info("Remote Host: "+serverHost);
severName = config.getInitParameter("server-name");
Log.web.info("Server Name: "+severName);
String timeoutInit = config.getInitParameter("timeout");
try{
timeout = Integer.parseInt(timeoutInit);
} catch (NumberFormatException nfe){
timeout = 60000;
}
Log.web.info("Timeout: "+timeout);
// test only use DEBUG-Mode
count++;
Log.web.debug("Servlet Instance Nr."+count);
number=count;
Log.web.debug("Servlet Nr."+number);
// prepare Servlet for callbacks
try{
UnicastRemoteObject.exportObject(this);
} catch(RemoteException re){
re.printStackTrace();
}
this.lookup(serverHost,severName);
try{
this.server.register(this);
Log.rmi.info("Servlet registred to "+severName);
} catch (RemoteException re){
Log.rmi.fatal("Register to ["+severName+"] failed!",re);
}
}
Here the output I get from Tomcat:
2001-10-01 11:56:46 - ContextManager: Adding context Ctx( /test )
0 DEBUG [main] hephaistos.log init - Log4J configuration laoded
21 INFO [main] hephaistos.web init - Remote Host: localhost
21 INFO [main] hephaistos.web init - Server Name: ServletServer
21 INFO [main] hephaistos.web init - Timeout: 80000
21 DEBUG [main] hephaistos.web init - Servlet Instance Nr.1
21 DEBUG [main] hephaistos.web init - Servlet Nr.1
241 INFO [main] hephaistos.rmi init - Servlet registred to ServletServer
2001-10-01 11:56:47 - PoolTcpConnector: Starting HttpConnectionHandler
on 8080
2001-10-01 11:56:47 - PoolTcpConnector: Starting Ajp12ConnectionHandler
on 8007
9594 DEBUG [Thread-21] hephaistos.log init - Log4J configuration laoded
9594 INFO [Thread-21] hephaistos.web init - Remote Host: null
9594 INFO [Thread-21] hephaistos.web init - Server Name: null
9594 INFO [Thread-21] hephaistos.web init - Timeout: 60000
9594 DEBUG [Thread-21] hephaistos.web init - Servlet Instance Nr.2
9594 DEBUG [Thread-21] hephaistos.web init - Servlet Nr.2
11868 ERROR [Thread-21] hephaistos.rmi lookup - Lookup for [null] failed!
java.rmi.UnknownHostException: Unknown host: null; nested exception is:
java.net.UnknownHostException: null
java.net.UnknownHostException: null
at java.net.InetAddress.getAllByName0(InetAddress.java:571)
.....
Thread [main] is launched on tomcat's startup, Thread [21] on the first
request for this servlet.
I don't understand why tomcat has initialized another intance of the
servlet, he does it for every new request.
If I don't read any init-params tomcat only uses one instance, even if I
would implement the SingleThreadModel.
What's wrong here?!
Alessandro Di Maria