public void init(ServletConfig cnf) throws ServletException {
super.init(cnf);
ServletContext cnt=cnf.getServletContext();
ContextObject obj=new ContextObject();
obj.startTimeStamp();
cnt.setAttribute("obj",obj);
System.out.println("ContextObjectServlet.init()");
}init中的ServletConfig cnf是参数还是什么???参数能调用方法么???cnf.getServletContext();另外setAttribute()方法是什么意思???感谢老鸟!!!!!!
super.init(cnf);
ServletContext cnt=cnf.getServletContext();
ContextObject obj=new ContextObject();
obj.startTimeStamp();
cnt.setAttribute("obj",obj);
System.out.println("ContextObjectServlet.init()");
}init中的ServletConfig cnf是参数还是什么???参数能调用方法么???cnf.getServletContext();另外setAttribute()方法是什么意思???感谢老鸟!!!!!!
cnf.getServletContext(); 可以的 对象作为参数的时候,可以调用它自己的方法.
setAttribute()方法是什么意思???这个就查api吧
给你个学习的方法:碰到java本身的类里面没有见过的方法,去查API文档.
2.是对象就能调用方法
3.cnf.getServletContext()--获得servlet上下文
4.setAttribute()--在上下文中计入键和值
,然后你当然就可以调用这个对象的任何可以调用的方法
另外setAttribute()方法是什么意思??? Binds an object to a given attribute name in this servlet context。相信LZ可以看懂,SetAttribute("","");通俗点说就是给Obj取个别名,当然这样只是便于理解。(不是想误导你)