java如何根据后台添加信息生成前台html页面
我想通过后台当我添加完,提交后就会在前台生成一个html的静态页面
比如我添加了一篇文章是XX,平时我们是通过wenzhang.do?action=view&id=xx
但是我要生成静态页面,让客户看到的是静态页面,提高访问速度等;
应该怎样做呢?
我到网上找了很多资料看,有些生成html是只能生成index的页面,后面要生成某个文件夹里面的就不能用了。。
请高手指教
[解决办法]
竹子写过一篇,用 httpClient来生成
[解决办法]
给你一个类GetStaticPage,好像需要用到一两个包commons-httpclient-3.0.jar之类的,你自己找找
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()); } } }
[解决办法]
关注中
[解决办法]