当前位置: 首页 > 图文教程 > 网络编程 > JSP > 通用大型网站页面静态化解决方案

JSP
解决JSP中使用request乱码问题
高性能、高弹性JSP和Servlet性能优化
解决JSP开发Web程序中文显示三种方法
实例讲解在JSP开发中的对象和范围属性
JSP+XML实现网页内容动态显示的方案
weblogic的jsp问题解决方法
JSP处理异常及一些高级主题
JavaBean 在jsp和serlvle中传递技术要点
JSP和Servlet对中文的处理过程
用 servlet 将jsp文件内容转为html
JSP动态网站环境搭建的详细步骤
JSP/Servlet/JSF:自定义标签
Jsp常用功能:CSV文件的生成与分析
Jsp页面实现文件上传下载
JSP网站开发环境的目录结构标准
Windows 2000 server下搭建JSP网站环境
JSP教程:tomcat配置数据库连接池
tomcat下post方式提交服务器乱码
jsp环境下FCKeditor编辑器的应用
JSP网站开发环境配置和使用fckeditor

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 145 ::
收藏到网摘: n/a

在开发大型网站时,避免不了处理大量的页面静态化操作,这样方便加快网站访问速度与流量分流,那么如何来实现呢?其实说白了比较简单,网站静态化主要包括以下几方面的工作 多个文件服务器读写,这里可采用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中,然后通过调度中心异步执行,可用我在博客中说道的另外一篇文章解决即可