<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Welcome 布拉格

    BlogJava 首頁 聯系 聚合 管理
      6 Posts :: 13 Stories :: 15 Comments :: 0 Trackbacks

    package util.web;

    import java.io.*;

    public class Util {
    ???
    ??? /**
    ???? * 刪除文件
    ??? */
    ??? public static void rm(String filepath) throws IOException {
    ??????? File f = new File(filepath);//定義文件路徑
    ??????? if (f.exists()) {//判斷是文件還是目錄
    ??????????? if (f.isFile()) {
    ??????????????? f.delete();
    ??????????? } else if (f.isDirectory()) {
    ??????????????? if (f.listFiles().length == 0) {//若目錄下沒有文件則直接刪除
    ??????????????????? f.delete();
    ??????????????? } else {//若有則把文件放進數組,并判斷是否有下級目錄
    ??????????????????? File delFile[] = f.listFiles();
    ??????????????????? int i = f.listFiles().length;
    ??????????????????? for (int j = 0; j < i; j++) {
    ??????????????????????? if (delFile[j].isDirectory()) {
    ??????????????????????????? rm(delFile[j].getAbsolutePath());//遞歸調用del方法并取得子目錄路徑
    ??????????????????????? }
    ??????????????????????? delFile[j].delete();//刪除文件
    ??????????????????? }
    ??????????????? }
    ??????????? }
    ??????? }
    ??? }
    }


    <-@@@@@@@@@@@@@@@@@@@@@>

    package util.web;

    /**
    ?* 頁面計數器
    ?* @author Dave
    ?*/
    public class Pagination {

    ??? public static final int PAGE_SIZE = 15;

    ??? private int totalPages = 1;

    ??? private int currPage = 1;

    ??? private int totalRecords = 0;

    ??? private int firstRecord = 1;

    ??? private int lastRecord = 1;

    ??? private int pageSize = PAGE_SIZE;

    ??? public Pagination(int firstRecoder, int pageSize) {
    ??????? this.firstRecord = firstRecoder;
    ??????? this.pageSize = pageSize;
    ??? }

    ??? public int getFirstRecord() {
    ??????? return firstRecord;
    ??? }

    ??? public int getPageSize() {
    ??????? return pageSize;
    ??? }

    ??? public int getTotalRecords() {
    ??????? return totalRecords;
    ??? }

    ??? public void setTotalRecords(int totalRecords) {
    ??????? this.totalRecords = totalRecords;
    ??????? if(totalRecords > 0){
    ??????????? init();
    ??????? }
    ??? }

    ??? public int getCurrPage() {
    ??????? return currPage;
    ??? }

    ??? public int getLastRecord() {
    ??????? return lastRecord;
    ??? }

    ??? public int getTotalPages() {
    ??????? return totalPages;
    ??? }

    ??? private void init() {
    ??????? int test;
    ??????? test = totalRecords % pageSize;
    ??????? totalPages = test == 0 ? totalRecords / pageSize : totalRecords / pageSize + 1;

    ??????? if (firstRecord >= totalRecords) {
    ??????????? firstRecord = (totalPages - 1) * pageSize + 1;
    ??????? }

    ??????? currPage = firstRecord / pageSize + 1;

    ??????? lastRecord = (firstRecord + pageSize) > totalRecords ? totalRecords : firstRecord + pageSize - 1;

    ??? }

    ??? /**
    ???? * 獲取數據查詢訪問的第一條記錄
    ???? * @return
    ???? */
    ??? public int getStartRow() {
    ??????? if(firstRecord<=1)
    ??????????? return 0;
    ??????? return this.firstRecord - 1;
    ??? }

    ??? public String getHeader() {
    ??????? return "<script language=\"JavaScript\">writeHeader(" + firstRecord + "," + lastRecord + "," + totalRecords + "," + pageSize + "," + currPage + "," + totalPages + ")</script>";
    ??? }

    ??? public String getFooter() {
    ??????? return "<script language=\"JavaScript\">writeFooter(" + currPage + "," + totalPages + "," + firstRecord + "," + pageSize + "," + totalRecords + ")</script>";
    ??? }

    }
    <#####################>
    package util.web;

    import java.io.IOException;

    import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    import javax.servlet.http.HttpServletRequest;

    /**
    ?* @author Dave
    ?*/
    public class CacheMappingFilter implements Filter {

    ??? //???? ----------------------------------------------------- Instance Variables

    ??? /**
    ???? * The default character encoding to set for requests that pass through
    ???? * this filter.
    ???? */
    ??? protected String enable = null;

    ??? /**
    ???? * The filter configuration object we are associated with. If this value
    ???? * is null, this filter instance is not currently configured.
    ???? */
    ??? protected FilterConfig filterConfig = null;

    ??? /**
    ???? * Should a character encoding specified by the client be ignored?
    ???? */
    ??? protected boolean ignore = true;

    ??? //???? --------------------------------------------------------- Public Methods

    ??? /**
    ???? * Take this filter out of service.
    ???? */
    ??? public void destroy() {

    ??????? this.enable = null;
    ??????? this.filterConfig = null;

    ??? }

    ??? /**
    ???? * Select and set (if specified) the character encoding to be used to
    ???? * interpret request parameters for this request.
    ???? *
    ???? * @param request The servlet request we are processing
    ???? * @param result The servlet response we are creating
    ???? * @param chain The filter chain we are processing
    ???? *
    ???? * @exception IOException if an input/output error occurs
    ???? * @exception ServletException if a servlet error occurs
    ???? */
    ??? public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

    ??????? //???? Pass control on to the next filter
    ??????? //

    ??????? //request.setCharacterEncoding("utf-8");

    ??????? HttpServletRequest req = (HttpServletRequest) request;
    ??????? String path = req.getServletPath();
    ??????? String pageCacheEnable = (String)StaticValue.cacheMapping.get(path);
    ??????? if ((!path.startsWith("/admin")) && path.endsWith(".jsp")&&req.getParameter("makeCache")==null&&"true".equals(pageCacheEnable)) {
    ??????????????? path = path.replaceAll(".jsp", "_cache.html");
    ????????????????? //? System.out.println(path);
    ??????????????????? //?? System.out.println(req.getRequestURI());
    ???????????????????? //? System.out.println(req.getRequestURL());
    ??????????????? request.getRequestDispatcher("/cache"+path).forward(request, response);
    ??????? } else {
    ??????????? chain.doFilter(request, response);
    ??????? }

    ??? }

    ??? /**
    ???? * Place this filter into service.
    ???? *
    ???? * @param filterConfig The filter configuration object
    ???? */
    ??? public void init(FilterConfig filterConfig) throws ServletException {

    ??????? this.filterConfig = filterConfig;
    ??????? this.enable = filterConfig.getInitParameter("enable");

    ??? }

    }
    <%%%%%%%%%%%>


    package util.web;

    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.io.Writer;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.util.Date;

    public class StaticHtmlCache {

    ??? private static long star = 0;

    ??? private static long end = 0;

    ??? private static long ttime = 0;

    ??? //??? 返回html代碼
    ??? public static String getHtmlCode(String httpUrl) {
    ??????? Date before = new Date();
    ??????? star = before.getTime();
    ??????? String htmlCode = "";
    ??????? try {
    ??????????? InputStream in;
    ??????????? URL url = new java.net.URL(httpUrl);
    ??????????? HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    ??????????? connection = (HttpURLConnection) url.openConnection();
    ??????????? connection.setRequestProperty("User-Agent", "Mozilla/4.0");
    ??????????? connection.connect();
    ??????????? in = connection.getInputStream();
    ??????????? java.io.BufferedReader breader = new BufferedReader(new InputStreamReader(in, "UTF8"));
    ??????????? String currentLine;
    ??????????? while ((currentLine = breader.readLine()) != null) {
    ??????????????? htmlCode = htmlCode + currentLine + '\n';
    ??????????? }
    ??????? } catch (Exception e) {
    ??????????? e.printStackTrace();
    ??????? } finally {
    ??????????? Date after = new Date();
    ??????????? end = after.getTime();
    ??????????? ttime = end - star;
    ??????????? System.out.println("執行時間:" + ttime + "秒");
    ??????? }
    ??????? //System.out.print(htmlCode);
    ??????? return htmlCode;
    ??? }

    ??? //??? 存儲文件
    ??? public static synchronized void writeHtml(String filePath, String info, boolean override,String encoding) {

    ??????? Writer out = null;
    ??????? File afile = new File(filePath);
    ??????? try {
    ??????????? boolean isExit = afile.exists();
    ??????????? if (isExit) {
    ??????????????? if (override){
    ??????????????????? afile.delete();
    ??????????????????? afile.createNewFile();
    ??????????????? }
    ??????????? } else {
    ??????????????? afile.createNewFile();
    ??????????? }
    ???????????

    ??????????? out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(afile), encoding));
    ??????????? out.write(info);
    ??????????? out.flush();
    ???????????
    ??????? } catch (Exception ex) {
    ??????????? System.out.println(ex.getMessage());
    ??????? } finally {
    ??????????? try{out.close();}catch (Exception e) {
    ??????????? }
    ??????? }
    ??? }

    ??? public static void main(String[] args) {
    ??????? String url = "http://localhost:18080/zzesweb/index.jsp";
    ??????? writeHtml("d:/in2.htm", getHtmlCode(url), true,"utf-8");
    ??? }

    }

    posted on 2007-09-12 12:08 Welcome 閱讀(318) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 中文字幕不卡免费高清视频| 亚洲av日韩av无码av| 免费一级特黄特色大片| 免费国产成人午夜电影| 久久精品国产亚洲AV天海翼| 女人18毛片免费观看| 亚洲人成人伊人成综合网无码| 四虎影视免费在线| 亚洲av成本人无码网站| 免费A级毛片在线播放不收费| 黄色免费网站在线看| 亚洲成A人片在线观看无码3D| 免费中文字幕视频| 亚洲一区AV无码少妇电影☆| 秋霞人成在线观看免费视频| 亚洲午夜在线电影| 久久久久久99av无码免费网站 | 久久久久久久综合日本亚洲| 在线观看片免费人成视频无码| 久久国产精品亚洲一区二区| 亚洲一区二区三区免费观看 | 久久精品九九亚洲精品| 免费观看黄网站在线播放| 亚洲成av人片天堂网无码】| 亚洲午夜精品一级在线播放放| 在线观看特色大片免费网站| 亚洲午夜精品在线| 免费人成在线观看播放国产| 在线观看免费无码专区| 亚洲国产精品xo在线观看| 免费a级毛片网站| 久久久久高潮毛片免费全部播放 | 国产高清对白在线观看免费91| 亚洲AV日韩精品久久久久久久| 蜜桃视频在线观看免费网址入口| 一级毛片无遮挡免费全部| 久久亚洲AV成人无码国产| 国产成人在线观看免费网站| a色毛片免费视频| 亚洲日本VA中文字幕久久道具| 亚洲日韩国产成网在线观看|