<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)  編輯  收藏

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


    網站導航:
     
    主站蜘蛛池模板: 亚洲中文字幕久久精品蜜桃| 91精品手机国产免费| 亚洲成a人片在线观看无码| 久久ww精品w免费人成| 亚洲精品女同中文字幕| 久久亚洲精品中文字幕三区| 精品香蕉在线观看免费| 男女猛烈无遮掩视频免费软件| 亚洲天堂中文字幕| 四虎精品成人免费视频| 亚洲制服中文字幕第一区| 日本一道本高清免费| 一级毛片免费观看| 日韩色视频一区二区三区亚洲| 亚洲综合国产精品| 亚洲av麻豆aⅴ无码电影| 粉色视频免费入口| 久久亚洲日韩精品一区二区三区 | 国产精品美女午夜爽爽爽免费| 色一情一乱一伦一视频免费看| 亚洲视频一区二区在线观看| 亚洲日韩中文字幕日韩在线| 一区二区三区免费看| 色天使亚洲综合在线观看| 亚洲精品~无码抽插| 222www免费视频| 一个人看的www视频免费在线观看| 亚洲狠狠成人综合网| 亚洲av无码一区二区三区乱子伦| 在线观看免费精品国产| 日韩欧毛片免费视频| 成人久久免费网站| 免费国产a理论片| 国产亚洲精品成人AA片| 久久久久亚洲av无码专区导航| 久久久久亚洲AV综合波多野结衣 | 久久久免费的精品| 国产精品免费一区二区三区| 亚洲色大成网站WWW久久九九| 777爽死你无码免费看一二区 | 国产日本一线在线观看免费|