首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

利用servlet在tomcat启动时初始化有关信息(转)

2012-09-14 
利用servlet在tomcat启动时初始化相关信息(转)网站建设时需要用到这样的功能:显示网站(或系统)的启动时间,

利用servlet在tomcat启动时初始化相关信息(转)

网站建设时需要用到这样的功能:显示网站(或系统)的启动时间,至今已运行了时间。曹海峰的思路是web.xml中配置servlet,在网站启动时调用servlet的init()方法,初始化相关数据。具体代码如下。

1、web.xml添加

public class GetCmsStartTimeServlet extends HttpServlet {public void init() throws ServletException{SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");String starttime = sdf.format(new Date());ServletContext application=this.getServletContext();application.setAttribute("starttime", starttime);}}

?

热点排行