| 您的位置:首页 > 文档 > java > |
文章分类热门文章 |
用Java Servlet构建广告系统(2)创建:2005-10-28 00:09:07 作者:Unlinux 来自: http://www.Unlinux.com hashtable.remove("log"); } return true; } private Hashtable getConfig(String s)//取得配置 { Hashtable hashtable = (Hashtable)cfgs.get(s); if(hashtable != null)//如果配置不为空 try { String s1 = (String)hashtable.get("edited"); File file = new File(s); if(!s1.equals(String.valueOf(file.lastModified()))){ file://如果s1的值不等于文件最后一次修改的值,则hashtable的内容为空值 hashtable = null; } catch(Exception _ex)//捕获Exception _ex错误 { hashtable = null; } if(hashtable != null) return hashtable; hashtable = new Hashtable(); if(!readConfig(s, hashtable)) { return null; } else { cfgs.put(s, hashtable); return hashtable; } } public void init(ServletConfig servletconfig)//初始化配置参数 throws ServletException { file://如果出错,抛出一个ServletException错误 super.init(servletconfig); separator = System.getProperty("file.separator");//取得分隔符 cfgs = new Hashtable();//设置配置变量 logs = new Hashtable();//设置日志变量 System.out.println("© Wayne Zheng ");//屏幕输出我的邮箱地址 } public void destroy() { } public void doPost(HttpServletRequest request, HttpServletResponse response) file://发送POST请求 throws ServletException, IOException { doGet(request, response); } public void doGet(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse) file://读取GET throws ServletException, IOException { String strConfig = httpservletrequest.getQueryString(); file://读取请求字符串 if(strConfig == null)//如果字符串为空 strConfig = "";//那么设置strConfig为空 if(strConfig.length() == 0) file://如果strConfig长度为零,那么显示错误信息 { errorMessage("无配置信息!", httpservletresponse); return; } String strConfig1 = getFromQuery(s, "config=");//同上 if(strConfig1.length() == 0){ strConfig1 = strConfig; Hashtable hashtable = getConfig(strConfig1); if(hashtable == null) { errorMessage("配置信息错误!", httpservletresponse); return; } if(hashtable.get("dir") == null) file://如果哈希表中dir为空值,则输出错误信息 { errorMessage("不能打开数据目录", httpservletresponse); return; } String strConfigMode2 = getFromQuery(strConfig, "mode=");//读取配置中的mode值 if(strConfigMode2.length() == 0){//如果没有mode值 strConfigMode2 = "1";//则设mode值为1 String strConfigId3 = getFromQuery(strConfig, "id=");//读取配置中的id值 if(strConfigId3.length() == 0){ file://如果没有id值 strConfigId3 = "1";//则设id值为1 HttpSession httpsession = httpservletrequest.getSession(true); if(strConfigMode2.equals("1")) file://如果strConfigMode2的值为1,则显示banner广告 { showBanner(hashtable, strConfigId3, httpsession, httpservletrequest, httpservletresponse); return; } else file://否则转向banner所指的站点 { goToSite(hashtable, strConfigId3, httpsession, httpservletrequest, httpservletresponse); return; } } private void goToSite (Hashtable hashtable, String s, HttpSession httpsession, HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)//转向站点 throws IOException file://如果有任何错误,抛出IOException错误 { String sitename1;//定义站点名 if(httpsession == null)//如果httpsession为空 转载自:http://www.unlinux.com/doc/java/20051028/5779.html 【评论】 【加入收藏夹】 【大 中 小】 【打印】 【关闭】 ※ 相关链接
|