获取动态页面模板再生成静态页面

<%
String url = "http://localhost/";
HttpClient httpclient=new HttpClient();
GetMethod getMethod=new GetMethod(url);
int statusCode=httpclient.executeMethod(getMethod);
byte[] responseBody = getMethod.getResponseBody();
String content = new String(responseBody,"GBK");
getMethod.releaseConnection();

String filePath = request.getRealPath(File.separator).replace("\\",File.separator) + "gen.html";
writeHtml(filePath, content);
%>
<%!
synchronized void writeHtml(String filePath, String info) {
try {
String path = filePath.substring(0, filePath.lastIndexOf(File.separator));
File writePath = new File(path);
if (!writePath.exists()) {
    writePath.mkdirs();
}
File writeFile = new File(filePath);
boolean isExit = writeFile.exists();
if (isExit != true) {
writeFile.createNewFile();
} else {
writeFile.delete();
writeFile.createNewFile();
}
OutputStreamWriter write = new OutputStreamWriter(new FileOutputStream(filePath),"GBK");
BufferedWriter writer=new BufferedWriter(write);
writer.write(info);
writer.close();
} catch (Exception ex) {
System.out.println(ex.getMessage()+" File:"+filePath);
}
}
%>

你可能感兴趣的:(html)