当前位置: 移动技术网 > IT编程>开发语言>Java > 通用大型网站页面静态化解决方案

通用大型网站页面静态化解决方案

2017年12月12日  | 移动技术网IT编程  | 我要评论
多个文件服务器读写,这里可采用smb协议
页面静态化,可采用freemarker开源框架
如果考虑到大量的读写请求,则将请求分布式或采用调度的办法来解决
第一点我们首先应该考虑文件服务器与静态页面的映射关系,即什么文件应该读写到哪台服务器,这个关系最简单的办法是随机映射,然后将映射关系保存到数据库中即可,smb常用的操作代码如下:
复制代码 代码如下:

    public static boolean exists(string filepath,string username,string pwd) throws exception
    {
    smbfile file = new smbfile("smb://"+username+":"+pwd+"@"+filepath);
try{
    return file.exists();
}catch(exception ex){
    return false;
}
    }

public static boolean filerename(string filepath,string newfilename,string username,string pwd)
    {
    try{
         smbfile f=new smbfile("smb://"+username+":"+pwd+"@"+filepath);
         if(f.isfile()){
     string str=filepath.substring(0,filepath.lastindexof("/"));
     str="smb://"+username+":"+pwd+"@"+str+"/"+newfilename;
     f.renameto(new smbfile(str));
         }else if(f.isdirectory()){
         string str=filepath.substring(0,filepath.length()-1);
         str=filepath.substring(0,str.lastindexof("/"));
         str="smb://"+username+":"+pwd+"@"+str+"/"+newfilename;
         f.renameto(new smbfile(str));              
         }
     return true;
    }catch(exception ex){
        return false;
    }
    }

public static void mkdir(string dir,string username,string pwd)
{
try{
     smbfile f=new smbfile("smb://"+username+":"+pwd+"@"+dir);
     if(!f.exists())
f.mkdir();
}catch(exception ex)
{
}
}

public static void mkfile(string filepath,string username,string pwd)
{
try
{
     smbfile f=new smbfile("smb://"+username+":"+pwd+"@"+filepath);
     if(!f.exists())
f.createnewfile();
}catch(exception ex)
{
}
}

public static void mkfile(string filepath,string username,string pwd,string content)
{
try
{
     smbfile f=new smbfile("smb://"+username+":"+pwd+"@"+filepath);
     if(!f.exists())
f.createnewfile();
writefile(filepath,content,username,pwd);
}catch(exception ex)
{
}
}

public static boolean isdir(string filepath,string username,string pwd) throws exception
{
string dir="smb://"+username+":"+pwd+"@"+filepath;
smbfile f=new smbfile(dir);
return f.isdirectory();
}

第二点,页面静态化可由freemarker生成,freemarker的使用比较简单,我这里不再啰嗦,重复说了
第三点,调度中心,或把静态化的请求先保存到task中,然后通过调度中心异步执行,可用我在博客中说道的另外一篇文章解决即可

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网