是否有可能在启动Servlet和同一web.xml中的正常Request,Response Servlet上加载?

时间:2014-12-10 10:22:26

标签: java servlets servlet-filters servlet-listeners

对于客户端和服务器的实现,我需要在部署后立即启动servlet,另一个应该等待请求。可能吗?如果什么是正确的实施方式。

<?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>

上面是我的web.xml。我已经看到了侦听器的某些用法。

我是servlet的新手。需要帮助。

1 个答案:

答案 0 :(得分:0)

小模板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>