public class Server extends HttpServlet{ public Server(){ } public void init(ServletConfig sc) throws ServletException { //服务在此开始 } public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException{} public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException{ } }
<servlet>
<servlet-name>myserver</servlet-name>
<servlet-class>server.myserver</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
你的服务可以在myserver这个servlet的init中启动。
public Server(){ }
public void init(ServletConfig sc) throws ServletException {
//服务在此开始
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws IOException, ServletException{}
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws IOException, ServletException{ }
}