JAVA用于生成静态页面

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

<无详细内容>
package com.lhsoft; 
 import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.sql.ResultSet; import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.Date; 
 /** 
 *   
 * @author 程志平 
 *  
 * 
 */ public class OperRateAction { 
    private static int PAGESIZE = 10; 
    private static int PAGEINDEX = 10; 
    /** 
     * 该方法用于创建静态页面根据将生成相应页数的页面 
     * @param path 文件存放路径 
     * @param filename 页面文件名 
     * @param statichtml 页面内容 
     * @param i 页面后追加的数字 
     * @param size 每页显示记录条数 
     * @author nickCheng 
     *  
     * */
    private static void createStaticHtml(String path,String filename,StringBuffer statichtml,int i,int size){ 
        if(size > 0){ 
            PAGESIZE = size; 
            PAGEINDEX = size; 
        } 
        int countRow = getRowCount(); 
        int pages = (int)(countRow / PAGESIZE); 
        if(countRow > pages * PAGESIZE) pages = pages + 1; 
          
        String  filepath = "D:"+File.separator+"mytable"+File.separator+"mytable"+i+".html"; 
        if(path != null && !"".equals(path)){ 
            filepath = path+File.separator+filename+i+".html"; 
        } 
        statichtml.append("<tr>"); 
        int j = i-1; 
        int k = i+1; 
        String proPage = filename+j+".html"; 
        String nextPage = filename+k+".html"; 
        if(j == 0) 
            proPage = "javascript:showMsg(0);"; 
        if(k == pages) 
            nextPage = "javascript:showMsg(1);"; 
        int pagess = pages -1; 
        String firstpage = filename+1+".html"; 
        String lastpage = filename+pagess+".html"; 
        statichtml.append("<td colspan='13' style='text-align: center;'><a href='"+firstpage+"'>首页</a>&nbsp;<a href='"+proPage+"'>上一页</a>&nbsp;&nbsp;<a href='"+nextPage+"'>下一页</a>&nbsp;<a href='"+lastpage+"'>最后一页</a>当前为第"+i+"页&nbsp;共"+pagess+"页</td>"); 
        statichtml.append("</tr>"); 
        statichtml.append("</tbody>"); 
        statichtml.append("</table></body></div></html>"); 
        File file =new File(filepath); 
            FileWriter filewriter; 
            try { 
                if(file.exists()){ 
                    file.delete(); 
                    file.createNewFile(); 
                } 
                filewriter = new FileWriter(file, true); 
                filewriter.write(statichtml.toString()); 
                filewriter.close();  
            } catch (IOException e) { 
                e.printStackTrace(); 
            } 
    } 
    /** 
     * 格式化数据 当为日期时将格式为:“yyyy-MM-dd”这种形式 
     * 当出现“null”或者是空字串时替换成“&nbsp;” 
     *  
     * */
    private static String fomatData(Object data){ 
        String  formatdata = null; 
        if(data instanceof Date ){ 
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); 
            formatdata = format.format(data); 
        } 
        else{ 
            formatdata = (data == null || "".equals(data.toString()))?"&nbsp;":data.toString(); 
        } 
        return formatdata; 
    } 
    /** 
     * 获得记录条数 
     * */
    private static int getRowCount(){ 
        int rowCount = 0 ; 
        OperateDB db = new OperateDB(); 
        String sql = "select count(0) from mytable"; 
        db.Query(sql); 
        ResultSet rs = db.getRs(); 
        try { 
            rs.next(); 
            rowCount = rs.getInt(1);  
        } catch (SQLException e) { 
            e.printStackTrace(); 
        }  
        return rowCount; 
    } 
    /** 
     * 静态页面的拼接 
     * @param path 路径 
     * @param filename 静态文件名 
     * @param size 没有显示记录数 
     * */
    public static boolean publish(String path,String filename,String size){ 
        int pagesize= 0 ; 
        if(size !=null && !"".equals("")){ 
            pagesize= Integer.valueOf(size); 
            if(pagesize > 0){ 
                PAGESIZE = pagesize; 
                PAGEINDEX = pagesize; 
            } 
        } 
        OperateDB db = new OperateDB(); 
        String sql = "select * from mytable"; 
        db.Query(sql); 
        StringBuffer statichtml = new StringBuffer(); 
        ResultSet rs = db.getRs(); 
        try { 
            int i = 1; 
            int countRow = getRowCount(); 
            int pages = (int)(countRow / PAGESIZE); 
            if(countRow > pages * PAGESIZE) pages = pages + 1; 
              while(rs.next()) 
              { 
                  int currentrow = rs.getRow(); 
                  if(currentrow <= PAGEINDEX){ 
                      statichtml.append("<tr>"); 
                      statichtml.append("<td>"+fomatData(rs.getString("id"))+"</td>"); 
                      statichtml.append("<td>"+fomatData(rs.getDate("orig_time"))+"</td>"); 
                      statichtml.append("<td>"+fomatData(rs.getDouble("latitude"))+"</td>"); 
                      statichtml.append("<td>"+fomatData(rs.getDouble("longitude"))+"</td>"); 
                      statichtml.append("<td>"+fomatData(rs.getDouble("depth"))+"</td>"); 
                      statichtml.append("<td>"+fomatData(rs.getString("type_mag"))+"</td>"); 
                      statichtml.append("<td>"+fomatData(rs.getDouble("num_mag"))+"</td>"); 
                      statichtml.append("<td>"+fomatData(rs.getString("epicenter"))+"</td>"); 
                      statichtml.append("<td>"+fomatData(rs.getString("signs"))+"</td>"); 
                      statichtml.append("<td>"+fomatData(rs.getDate("intime"))+"</td>"); 
                      statichtml.append("<td>"+fomatData(rs.getString("gis_pic"))+"</td>"); 
                      statichtml.append("<td>"+fomatData(rs.getString("doc_path"))+"</td>"); 
                      statichtml.append("<td>"+fomatData(rs.getString("sm_content"))+"</td>"); 
                      statichtml.append("</tr>"); 
                      if(currentrow == PAGEINDEX){ 
                          StringBuffer headhtml = new StringBuffer(); 
                            headhtml.append("<html>"); 
                            headhtml.append("<head>"); 
                            headhtml.append("<title>"+filename+"</title>"); 
                            headhtml.append("<meta http-equiv='Content-Type' content='text/html; charset=gbk'>"); 
                            headhtml.append("<script>"); 
                            headhtml.append("function showMsg(i){if(i==0)alert('对不起,当前页已经是最上一页啦');else alert('对不起,当前页已经是最后一页啦');}"); 
                            headhtml.append("</script>"); 
                            headhtml.append("</head><body>"); 
                            headhtml.append("<div style='text-align:center;'>"); 
                            headhtml.append("<table width='800' border='1' cellspacing=0 cellpadding=0><thead><tr>"); 
                            headhtml.append("<th>ID</th>"); 
                            headhtml.append("<th>ORIGTIME</th>"); 
                            headhtml.append("<th>LATITUDE</th>"); 
                            headhtml.append("<th>LONGITUDE</th>"); 
                            headhtml.append("<th>DEPTH</th>"); 
                            headhtml.append("<th>TYPEMAG</th>"); 
                            headhtml.append("<th>NUMMAG</th>"); 
                            headhtml.append("<th>EPICENTER</th>"); 
                            headhtml.append("<th>SIGNS</th>"); 
                            headhtml.append("<th>INTIME</th>"); 
                            headhtml.append("<th>GISPIC</th>"); 
                            headhtml.append("<th>DOCPATH</th>"); 
                            headhtml.append("<th>SMCONTENT</th>"); 
                            headhtml.append("</thead><tbody>"); 
                          StringBuffer currenthtml = headhtml.append(statichtml); 
                          createStaticHtml(path,filename,currenthtml,i,pagesize); 
                          currenthtml.delete(0, Integer.MAX_VALUE); 
                          statichtml.delete(0, Integer.MAX_VALUE); 
                          i++; 
                          PAGEINDEX = PAGESIZE * i; 
                      } 
                  } 
              }  
              return true; 
        } catch (Exception e) { 
            System.out.println(e.getMessage()); 
            return false; 
        } 
    } 
    /** 
     * @param args 
     */
    public static void main(String[] args) { 
        publish(args[0],args[1],args[2]); 
    } 
  
}