请教init()的用法? 當Servlet被Servlet引擎載入後,接下來就是執行這個方法你可以重載它,做一些初始化動作,取值啊,建立連接啊什麼的都可以public init(ServletConfig config) throws ServletException{ super.init(); /* 你要做的初始化動作 */} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public void init(ServletConfig config) throws ServletException { System.out.println("The WSE system is initializing..."); super.init(config); String encoding = config.getServletContext().getInitParameter("charset"); String home = this.getInitParameter("home"); if (home != null) { getServletContext().setAttribute("HomeDir", home); } else { getServletContext().setAttribute("HomeDir", "c:\\WESPrj"); } System.out.println("HomeDir:" + home); // ÔÚÏßÓû§Áбí Set onlineUsers = new TreeSet(); this.getServletContext().setAttribute("onlineUsers", onlineUsers); // end //get mail host and authentication(user name and password) String mailhost = this.getInitParameter("mailhost"); System.out.println("mailhost:" + mailhost); getServletContext().setAttribute("MailHost", mailhost); String systememail = this.getInitParameter("systememail"); getServletContext().setAttribute("SystemEmail", systememail); System.out.println("systememail:" + systememail); String mailhostuser = this.getInitParameter("mailhostuser"); getServletContext().setAttribute("MailHostUser", mailhostuser); System.out.println("mailhostuser:" + mailhostuser); String mailhostpassword = this.getInitParameter("mailhostpassword"); getServletContext().setAttribute("MailHostPassword", mailhostpassword); System.out.println("mailhostpassword:" + mailhostpassword); String sendMailInterval = this.getInitParameter("sendmailinterval"); int interval = Integer.parseInt(sendMailInterval); System.out.println("interval:" + interval);} 关于Session的一个问题 struts2 设定action的接收方式 上传的文件怎么删不掉!!! 关于tomcat.很奇怪的问题 关于JS 判断值为空的问题 #欢迎讨论:如何加强基于jsp系统的安全性问题# 关于mvnforum连接oracle数据库的问题! 求大神指教。为什么不能算出购物车结果 各位高手,有关word的问题!给我点参考资料! weblogic中使用sendRedirect可不可以用相对路径 救助 用JSP(JAVA)写的从LOTUS NOTES 导入 ORACLE9I 数据库 提交中文---模糊查询---出现乱码~~~~高手指点啊!!!!!!!
super.init(config);
String encoding =
config.getServletContext().getInitParameter("charset"); String home = this.getInitParameter("home");
if (home != null) {
getServletContext().setAttribute("HomeDir", home);
} else {
getServletContext().setAttribute("HomeDir", "c:\\WESPrj");
}
System.out.println("HomeDir:" + home); // ÔÚÏßÓû§Áбí
Set onlineUsers = new TreeSet();
this.getServletContext().setAttribute("onlineUsers", onlineUsers);
// end //get mail host and authentication(user name and password)
String mailhost = this.getInitParameter("mailhost");
System.out.println("mailhost:" + mailhost);
getServletContext().setAttribute("MailHost", mailhost); String systememail = this.getInitParameter("systememail");
getServletContext().setAttribute("SystemEmail", systememail);
System.out.println("systememail:" + systememail); String mailhostuser = this.getInitParameter("mailhostuser");
getServletContext().setAttribute("MailHostUser", mailhostuser);
System.out.println("mailhostuser:" + mailhostuser); String mailhostpassword = this.getInitParameter("mailhostpassword");
getServletContext().setAttribute("MailHostPassword", mailhostpassword);
System.out.println("mailhostpassword:" + mailhostpassword);
String sendMailInterval = this.getInitParameter("sendmailinterval");
int interval = Integer.parseInt(sendMailInterval);
System.out.println("interval:" + interval);
}