我想通过后台当我添加完,提交后就会在前台生成一个html的静态页面
比如我添加了一篇文章是XX,平时我们是通过wenzhang.do?action=view&id=xx
但是我要生成静态页面,让客户看到的是静态页面,提高访问速度等;
应该怎样做呢?
我到网上找了很多资料看,有些生成html是只能生成index的页面,后面要生成某个文件夹里面的就不能用了。。
请高手指教
比如我添加了一篇文章是XX,平时我们是通过wenzhang.do?action=view&id=xx
但是我要生成静态页面,让客户看到的是静态页面,提高访问速度等;
应该怎样做呢?
我到网上找了很多资料看,有些生成html是只能生成index的页面,后面要生成某个文件夹里面的就不能用了。。
请高手指教
import java.io.*;import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;import com.qingke.logs.Logs;public class GetStaticPage {
String host;
int port;
public String getHost() {
return host;
} public void setHost(String host) {
this.host = host;
} public int getPort() {
return port;
} public void setPort(int port) {
this.port = port;
}
public void jspToHtml(String jspPath,String jspName,String htmlPath,String htmlName){
try{
HttpClient client = new HttpClient();
client.getHostConfiguration().setHost(host,port);
String allpath=jspPath+jspName;
String allpathto = htmlPath+htmlName;
GetMethod get = new GetMethod(allpath);
client.executeMethod(get);
StringBuffer resultBuffer = new StringBuffer();
BufferedReader in = new BufferedReader(new InputStreamReader(get.getResponseBodyAsStream(),"GBK"));
String inputLine = null;
while( (inputLine = in.readLine()) != null ){
resultBuffer.append(inputLine);
resultBuffer.append("\n");
}
in.close();
String s = resultBuffer.toString();
//String s = get.getResponseBodyAsString();
BufferedWriter bw = new BufferedWriter(new FileWriter(new File(allpathto)));
bw.write(s);
bw.close();
get.releaseConnection();
}catch (Exception ex ){
Logs.writerLog(ex.getMessage());
}
} }在JSP中用的时候GetStaticPage gethtml = new GetStaticPage();
String pathreal=request.getRealPath("");
gethtml.setHost("127.0.0.1");
gethtml.setPort(80);
gethtml.jspToHtml("/程序路径/","wenzhang.do?action=view&id=xx",pathreal+"\\你的路径\\",文件名+".html");
假设 有一个HTML文件 你用JAVA字符流把他读进来的时候变成字符串 然后再将该字符串中的一部分替换掉 就会形成一个新的字符串 然后再将该字符串写到一个新的HTML文件里更概括的说:设计图与汽车的关系