如题:
    html的模板如下
<html>
<head>
<title>${title}</title>
</head>
<body>
${content}
<{if test="false"}>
是:true
<{/if}>
<{else}>
是:false
<{/else}>
</body>
</html>
下面是我写的,只实现了${title}和${content}的东西。
public class SetHtml { public static void main(String[] args) throws Exception {
File oldFile = new File("MyHtml.html");
File newFile = new File("NewHtml.html");
Map<String, Object> map = new HashMap<String, Object>();
map.put("title", "测试标题");
map.put("content", "测试内容");
createHtml(oldFile,newFile,map);
}

private static void createHtml(File oldFile,File newFile,Map<String, Object> map) throws Exception {
long length = (long) oldFile.length();
if(length > 3000000) {
throw new Exception("文件过大");
}
int len = (int)length;
byte[] b = new byte[len];
InputStream is = new FileInputStream(oldFile);
is.read(b);
is.close();
String strHtml = new String(b);
Pattern pattern = Pattern.compile("\\$\\{\\s*(\\w+)\\s*\\}");
Matcher matcher = pattern.matcher(strHtml);
StringBuffer sb = new StringBuffer();
while(matcher.find()) {
matcher.appendReplacement(sb, map.get(matcher.group(1)).toString());
}
matcher.appendTail(sb);
newFile.createNewFile();
OutputStream os = new FileOutputStream(newFile);
// getIf(sb.toString());
// getElse(sb.toString());
os.write(sb.toString().getBytes());
os.close();
}}
实现后的HTML结果为<html>
<head>
<title>测试标题</title>
</head>
<body>
测试内容
<{if test="false"}>
是:true
<{/if}>
<{else}>
是:false
<{/else}>
</body>
</html>
用正则表达式,现在要弄if...else,判断<{if test="false"}>中test是否true,则显示相应的
请高手支援。。谢谢啊