用JavaServlet构建广告系统(2)

王朝java/jsp·作者佚名  2008-05-18
窄屏简体版  字體: |||超大  

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为空

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航