网上有两种方法。本人都是了为啥都没有print
方法1:
package handleSql;
import javax.servlet.http.HttpServlet;
public class Handle_run extends HttpServlet {
public Handle_run(){
System.out.println(“gogo”);
}
}
web.xml中配置
<servlet>
<servlet-name>Handle_run</servlet-name>
<servlet-class>handleSql.Handle_run</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
方法2:
package handleSql;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class PictureEngine implements ServletContextListener{
@Override
public void contextDestroyed(ServletContextEvent arg0) {
// TODO Auto-generated method stub
System.out.println(“exit”);
}
@Override
public void contextInitialized(ServletContextEvent arg0) {
// TODO Auto-generated method stub
System.out.println(“enter”);
}
}
web.xml中配置
<listener>
<listener-class>handleSql.PictureEngine</listener-class>
</listener>
方法1:
package handleSql;
import javax.servlet.http.HttpServlet;
public class Handle_run extends HttpServlet {
public Handle_run(){
System.out.println(“gogo”);
}
}
web.xml中配置
<servlet>
<servlet-name>Handle_run</servlet-name>
<servlet-class>handleSql.Handle_run</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
方法2:
package handleSql;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class PictureEngine implements ServletContextListener{
@Override
public void contextDestroyed(ServletContextEvent arg0) {
// TODO Auto-generated method stub
System.out.println(“exit”);
}
@Override
public void contextInitialized(ServletContextEvent arg0) {
// TODO Auto-generated method stub
System.out.println(“enter”);
}
}
web.xml中配置
<listener>
<listener-class>handleSql.PictureEngine</listener-class>
</listener>
解决方案
50
有什么报错吗?
extends ContextLoaderListener看看
extends ContextLoaderListener看看