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

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

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

    Welcome 布拉格

    BlogJava 首頁(yè) 聯(lián)系 聚合 管理
      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 {//若有則把文件放進(jìn)數(shù)組,并判斷是否有下級(jí)目錄
    ??????????????????? File delFile[] = f.listFiles();
    ??????????????????? int i = f.listFiles().length;
    ??????????????????? for (int j = 0; j < i; j++) {
    ??????????????????????? if (delFile[j].isDirectory()) {
    ??????????????????????????? rm(delFile[j].getAbsolutePath());//遞歸調(diào)用del方法并取得子目錄路徑
    ??????????????????????? }
    ??????????????????????? delFile[j].delete();//刪除文件
    ??????????????????? }
    ??????????????? }
    ??????????? }
    ??????? }
    ??? }
    }


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

    package util.web;

    /**
    ?* 頁(yè)面計(jì)數(shù)器
    ?* @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;

    ??? }

    ??? /**
    ???? * 獲取數(shù)據(jù)查詢?cè)L問的第一條記錄
    ???? * @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("執(zhí)行時(shí)間:" + ttime + "秒");
    ??????? }
    ??????? //System.out.print(htmlCode);
    ??????? return htmlCode;
    ??? }

    ??? //??? 存儲(chǔ)文件
    ??? 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 閱讀(321) 評(píng)論(0)  編輯  收藏

    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲无限乱码一二三四区| 亚洲成A人片在线观看无码3D| 亚洲精品高清国产一久久| 国产99精品一区二区三区免费| 国产jizzjizz免费视频| 欧美激情综合亚洲一二区| 免费观看一级毛片| 亚洲av无码无线在线观看| 国产美女a做受大片免费| 亚洲成av人片在www鸭子| 免费一级一片一毛片| 人人爽人人爽人人片av免费| 亚洲一级特黄大片在线观看| 丝袜捆绑调教视频免费区| 国产亚洲人成A在线V网站| 在线看片免费人成视频福利| 久久亚洲美女精品国产精品 | 精品国产亚洲第一区二区三区| 亚欧日韩毛片在线看免费网站| 亚洲精品国产精品乱码在线观看| 最近的2019免费中文字幕| 中文字幕亚洲精品| 免费国产作爱视频网站| 亚洲AV色无码乱码在线观看| 亚洲国产精品嫩草影院久久 | 最新中文字幕免费视频| 亚洲av成人一区二区三区观看在线| 国产中文字幕免费| 成人性做爰aaa片免费看| 亚洲日韩在线视频| 免费观看四虎精品国产永久| 中文字幕免费播放| 亚洲国产成人久久三区| jjzz亚洲亚洲女人| 午夜影院免费观看| 亚洲av日韩av永久无码电影| 亚洲成色在线综合网站| 久久久久久99av无码免费网站 | 久操免费在线观看| 亚洲人成色777777精品| 亚洲精品成人网站在线观看 |