在tomcat\conf\web.xml文件中,有一段这样的代码:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>这里说明的是当tomcat启动后运行的代码文件,你可以用你自己的文件名称代替。
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>这里说明的是当tomcat启动后运行的代码文件,你可以用你自己的文件名称代替。
解决方案 »
- 怎样在jsp页面中显示doc文件中的内容(doc文件中包含图片)?
- string.valueOf的功能是什么??
- jsp中能添加vb么
- hibernate包下载
- 郁闷中
- 有什么方法能让jsp的执行中延迟一点时间。
- 请教javamail收邮件如何判断新邮件的思路?
- jsp 连接 db2 的问题,,第三个跟头了。。这条路真难走..
- 为什么接收sina发出的邮件都是乱码呢??
- 同一表单点击不同提交按钮执行不同的程序怎么实现?
- 在bean里,用oracle的pool,getPooledConnection();应该在构造函数里建立,还在其实里?释放开pool是不是应该在 finalize() 里?
- 超级菜鸟问题,不要打我!一定要打的话,不要打脸!谢谢!-->如何在Tomcat中设置虚拟目录?
<servlet>
<servlet-name>myservlet</servlet-name>
<servlet-class>MyServlet</servlet-class>
<init-param>
<param-name></param-name>
<param-value></param-value>
</init-param>
<load-on-startup>4</load-on-startup>
</servlet>
然后再你的servlet的init()方法中调用你想要执行的代码!
public class ApplicationListenter implements javax.servlet.ServletContextListener {
public void contextInitialized ( javax.servlet.ServletContextEvent event ) { } public void contextDestroyed ( javax.servlet.ServletContextEvent event ) { }
}
然后在web.xml里面加
<listener>
<listener-class>ApplicationListenter</listener-class>
</listener>
这个的作用有点类似于asp的global.asa中的application_onstart和onend,具体的用法你在网上找找servlet2.3规范
import org.apache.catalina.*;
public class myTomcatListener implements LifecycleListener{
public void lifecycleEvent(LifecycleEvent event){
Lifecycle lifecycle = event.getLifecycle();
if (Lifecycle.START_EVENT.equals(event.getType())) {
if (lifecycle instanceof Server) {
//do what you want to do
}
}
}
}
然后在server.xml中,在
<Server port="8005" shutdown="SHUTDOWN" debug="0">
下面添加这样一段:
<Listener className="myTomcatListener" debug="0"/>