日期:2014-05-17  浏览次数:20749 次

java如何根据后台添加信息生成前台html页面
我想通过后台当我添加完,提交后就会在前台生成一个html的静态页面
比如我添加了一篇文章是XX,平时我们是通过wenzhang.do?action=view&id=xx
但是我要生成静态页面,让客户看到的是静态页面,提高访问速度等;
应该怎样做呢?
我到网上找了很多资料看,有些生成html是只能生成index的页面,后面要生成某个文件夹里面的就不能用了。。
请高手指教

------解决方案--------------------
竹子写过一篇,用 httpClient来生成
------解决方案--------------------
给你一个类GetStaticPage,好像需要用到一两个包commons-httpclient-3.0.jar之类的,你自己找找
Java code


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());
           }
        }

    

}

------解决方案--------------------
关注中
------解决方案--------------------
探讨
用freemarker试试。

------解决方案--------------------
freemarker是什么东西阿?
------解决方案--------------------
建议 看看 xsl应用 用xsl写个模板 然后后台内容提交后生成xml文件 调用模板转换成新的html
------解决方案--------------------
恩。。 简单点说
假设 有一个HTML文件 你用JAVA字符流把他读进来的时候变成字符串 然后再将该字符串中的一部分替换掉 就会形成一个新的字符串 然后再将该字符串写到一个新的HTML文件里

更概括的说:设计图与汽车的关系