Is it possible to have load on start up Servlet and a normal Request, Response Servlet in same web.xml?

367 Views Asked by At

For an implementation of client and server, I need to have on servlet to be started soon after deploying, another one should wait for the request. Is it possible? If what is right way to implement it.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>WiCodeRedeemRequest</display-name>
    <servlet-name>WiCodeRedeemRequest</servlet-name>
    <servlet-class>com.wicode.redeem.WiCodeRedeemRequest</servlet-class>
  </servlet>

  <servlet>
        <servlet-name>WiCode</servlet-name>
        <servlet-class>com.wicode.redeem.WiCode</servlet-class>
        <init-param>
          <param-name>Group</param-name>
          <param-value>1</param-value>
        </init-param>
        <init-param>
          <param-name>Instance</param-name>
          <param-value>1</param-value>
        </init-param>       
        <load-on-startup>1</load-on-startup>
    </servlet>

  <servlet-mapping>
    <servlet-name>WiCodeRedeemRequest</servlet-name>
    <url-pattern>/WiCode</url-pattern>
  </servlet-mapping>
</web-app>

Above is my web.xml. I have seen somewhere usage of listener.

I am new to servlet. Need help please.

1

There are 1 best solutions below

3
On

Small template xml..

<?xml version="1.0" encoding="UTF-8"?>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

  <servlet>
    <servlet-name>Servlet1</servlet-name>
    <servlet-class>com.wicode.redeem.WiCodeRedeemRequest</servlet-class>
    <load-on-startup>0</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>Servlet1</servlet-name>
    <url-pattern>/MappingForFirstServlet</url-pattern>
  </servlet-mapping>


  <servlet>
        <servlet-name>Servlet2</servlet-name>
        <servlet-class>com.wicode.redeem.WiCode</servlet-class>
     //What ever you want to initialize..
    </servlet>

  <servlet-mapping>
    <servlet-name>Servlet2</servlet-name>
    <url-pattern>Mapping URL</url-pattern>
  </servlet-mapping>
</web-app>