我现在正在做一个cms系统,想要生成静态页面。要生成静态页面可能还需要模板之类的,可是又不知道存储模板的时候都要把这个模板的什么东西存到数据库里,就是需要些什么字段,另外怎么把数据输入到模板里,而让它生成静态页面呢
ReadTemplates.java
package ball.news;
import java.io.*;
import java.util.*;
public class ReadTemplates
{
private String temp = null;
private Object a = new Object();
public ReadTemplates()
{
}
public String getTlpContent(String s)
{
if(temp == null)
synchronized(a)
{
if(temp == null)
try
{
System.out.println("----------------------------");
temp = a(s);
//System.out.println("test the temp"+temp);
}
catch(Exception e)
{
System.out.println("get tlpconente error"+e.getMessage());
}
}
return temp;
}
private synchronized String a(String s)
{
String s1 = null;
try
{
FileInputStream fileinputstream = new FileInputStream(s);
int i = fileinputstream.available();
byte abyte0[] = new byte[i];
fileinputstream.read(abyte0);
fileinputstream.close();
s1 = new String(abyte0);
}
catch(IOException e)
{
System.out.println("ioexception error"+e.getMessage());
}
return s1;
}
}
再把读取到的模板中的你想要替换掉的比如新闻标题,内容等的东西替换掉,用下面这个类
package ball.news;
import java.io.*;
import news.ReadTemplates;
public class ReplaceAll
{
private static Object a = new Object();
public ReplaceAll()
{
}
public String replace(String content,String flag,String temp)
{
String str = null;
try
{
//System.out.println("before-----"+content);
String s1 = content;
str = s1.replaceAll(flag,temp);
// System.out.println("replace after-----"+str);
}
catch(Exception e)
{
System.out.println("replace all error:"+e.getMessage());
}
return str;
}
private static void a(String s)
{
File file = new File(s);
if(!file.exists())
file.mkdirs();
}
}
然后生成HTML
WriteHtml.java
package ball.news;
import java.io.*;
public class WriteHtml
{
public WriteHtml()
{
}
public static void save(String s, String s1, String s2)
{
try
{
a(s1);
FileOutputStream fileoutputstream = new FileOutputStream(s1 + s2);
byte abyte0[] = s.getBytes();
fileoutputstream.write(abyte0);
fileoutputstream.close();
}
catch(IOException e)
{
System.out.println("write html error"+e.getMessage());
}
}
private static void a(String s)
{
try
{
File file = new File(s);
if(!file.exists())
file.mkdirs();
}
catch (Exception e)
{
System.out.println("mkdirs error!"+e.getMessage());
}
}
}
有点似懂非懂,还是不知道模板是怎么回事。高手请指点。
在ReadTemplates.java 这个文件里,temp就代表了模板的名字吗。
不好意思,我比较笨,说具体一点好吗。
这些类具体怎么调用,参数指的是什么还是有点一知半解,
另外生成一次静态页面就要读一次模板吗
帮顶一下吧,苦恼啊
模板技术只是个大概的方向,实现的方案多得很。
网上看了很多,模板似乎是以html形式存在的
大侠们有更多好的看法,麻烦分享一下吧。谢谢
liugezhang@hotmail.com
或者 fastm
表列的数量是否直接响查询速度 如何用java语言实现端口扫描器 2009第一贴,散发攒祝福,hoho~~~~ vb查询语法错误iif(sql2000) 哪位大哥能给个i/o中 复制文件和文件夹的实例 文字复制 急 在线等 明天就要回家了。 Delphi链接ACCESS数据库问题(有代码) 年初加班贴 09了,依然奋斗在前线 元旦了,同学都休息,就我一个写程序,不爽,散分 急,,管道获取子进程输出的奇怪问题 高读定位在自适应 急需bcb 帮助文件 新一年,新的开始! start with ... connect by 层次查询的用法报错:ORA-01436: CONNECT BY loop in user data SQL 急 谁能给我讲下呀 为了学C语言买单片机可以吗? 触发器中如何获取说修改的行的信息 隐式链接dll,当应用程序调用完dll中某个函数,是否会自动free这个dll?即这个dll是否会释放内存。隐式链接与显式链接,效率怎样? 程序员的梦 元旦快乐 org.hibernate.StaleStateException: Unexpected row count: 0 expected: 1 留言评论应该注意什么? 一篇文单中的图片是随文章一起放到数据库还是直接放相应文件夹? 哪里可以找到嵌入式兼职 不同id调用相同的函数如何取得各自的值,请教 求教一个MFC的小问题 谁有jquery 的资料啊 (最好是例子,详细怎么用的) 元旦!有多少人像我一样宅在家里?还有加班的么?