用户操作
[留言]  [发消息]  [加为好友] 
订阅我的博客
XML聚合    FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
lindazch的公告
文章分类
    技术
    存档

    原创  jsp (页面静态化) 收藏

    /**
     *
     */
    package test;

    /**

     *字符替换
     */
    public class ReplaceAll {
        public ReplaceAll()
        {
        }

        public static String replace(String s, String s1, String s2)
        {
            if(s == null)
                return null;
            StringBuffer stringbuffer = new StringBuffer();
            int i = s.length();
            int j = s1.length();
            int k;
            int l;
            for(k = 0; (l = s.indexOf(s1, k)) >= 0; k = l + j)
            {
                stringbuffer.append(s.substring(k, l));
                stringbuffer.append(s2);
            }

            if(k < i)
                stringbuffer.append(s.substring(k));
            return stringbuffer.toString();
        }
    }
     ——————————————————————————————————

    import javax.servlet.http.*;

    import java.util.Calendar;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;

    Calendar calendar=Calendar.getInstance();
       String fileName=String.valueOf(calendar.getTimeInMillis())+".html";

     String tempFile=request.getRealPath("/template")+"\\profession.template";

    try {
         String tempContent="";
         FileInputStream fileinputstream=new FileInputStream(tempFile);
         int length=fileinputstream.available();
         byte bytes[]=new byte[length];
         fileinputstream.read(bytes);
         fileinputstream.close();
         tempContent=new String(bytes);
         //tempContent.replaceAll("\\<%title%>",pform.getPname());
         tempContent=ReplaceAll.replace(tempContent,"<$title$>",pform.getPname());
         tempContent=ReplaceAll.replace(tempContent,"<$ptype$>",pform.getPtype());
         tempContent=ReplaceAll.replace(tempContent,"<$place$>",pform.getPlace());
         tempContent=ReplaceAll.replace(tempContent,"<$content$>",pform.getPdetail());
         tempContent=ReplaceAll.replace(tempContent,"<$pamount$>",pform.getPamount());
         fileName=request.getRealPath("/news/")+"/"+"profession\\"+fileName;
         FileOutputStream fileoutputstream=new FileOutputStream(fileName);
         byte tag_bytes[]=tempContent.getBytes();
         fileoutputstream.write(tag_bytes);
         fileoutputstream.close();
        //  WriteFile.writeInFile(pform.getPname(),pform.getPdetail(),tempFile,fileName,"profession\\",request);
       }
       catch (Exception e) {
             e.printStackTrace();
       }

    发表于 @ 2007年08月13日 14:35:00 | 评论( loading... ) | 编辑| 举报| 收藏

    新一篇:常用的开源网站链接

    • 发表评论
    • 评论内容:
    •  
    Copyright © lindazch
    Powered by CSDN Blog