亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? filehttprequesthandler.java

?? 這是一個我找的基于java編寫的web源碼
?? JAVA
字號:
package webServer;

import HTTP.*;
import java.net.*;
import java.util.*;
import java.io.*;

import org.w3c.dom.*;

/**http://www.codefans.net
 * Handles requests for files.  This can't dynamicly generate content.
 * A short configuration file is in data\fileHandlerConfig.xml.
 */
public class FileHTTPRequestHandler implements HTTPRequestHandler
{
 private static final File CONFIG_FILE = new File("data\\fileHandlerConfig.xml");
 private static String targetDirectory = loadConfigurationAndGetTargetDirectory();

    private static String loadConfigurationAndGetTargetDirectory()
    {
        String result = "public_html";
        try
        {
            Document doc = XMLParser.getDocumentFor(CONFIG_FILE);
            NodeList nl = doc.getElementsByTagName("targetDirectory");
            if (nl.getLength() > 0)
            {
                Element e = (Element)nl.item(0);
                String dir = e.getAttribute("value");
                if (dir != null)
                {
                    result = dir;

                    // Be flexible if the user thought he should include a trailing slash.
                    if (result.endsWith("\\") || result.endsWith("/"))
                        result = result.substring(0, result.length() - 1);
                }
            }
        }
        catch (Throwable t)
        {
            t.printStackTrace();
            System.err.println("Unable to load configuration from "+CONFIG_FILE);
        }
        return result;
    }

    public boolean canHandle(HTTPRequest request)
    {
        return true;
    }

    /**
     * Gets HTML formatted info for the specified file
     */
    private String getFileInfoContentFor(File parent,File f,boolean needsDirectoryNameInRelativeAddresses)
    {
        String hrefPath = f.getName();

          if (needsDirectoryNameInRelativeAddresses)
          {
              hrefPath = parent.getName() + "/" + hrefPath;
          }
        String result = "<a href=\"" + hrefPath + "\">" + f.getName() + "</a>";


          return result;
    }

    /**
     * Tries to get contents from an index page within the specified directory.
     * @return null if no index page is found.
     */
    private byte[] getIndexPageContentsForDirectory(File dir)
    { 
            String []indexPageNames = new String[]
        {"index.html","index.htm","default.html","default.htm"}; 

      byte[] result = null;
        for (String pageName: indexPageNames)
        {
          result = getFileContents(dir, pageName);
          if (result!=null)
            return result;
        }

      return null;
    }

    /**
     * Automatically generates indexing content for a directory.
     * @param requestPath may seem redundant but it is needed to 
     * determine if the browser needs the directory name in relative addresses.  
     * The directory name is needed in relative addresses if and only if '/' is not 
     * at the end of the request path. 
     */
    private byte[] getContentForDirectory(File dir,boolean needsDirectoryNameInRelativeAddresses)
    {
        if (!dir.isDirectory())
        {
            System.err.println("FileHTTPRequestHandler getContentForDirectory expected a directory instead of ");
        }
        byte[] indexPageContents = getIndexPageContentsForDirectory(dir);
        if (indexPageContents != null)
            return indexPageContents;
       try
       {
           ByteArrayOutputStream bout = new ByteArrayOutputStream();
           PrintStream out = new PrintStream(bout);
           File[] files = dir.listFiles();
           out.println("<html>");
           out.println(" <head>");
           out.println("  <title>Directory '"+dir.getName()+"'</title>");
           out.println(" </head>");
           out.println("<body>");
           out.println("  <h1>Directory '" + dir.getName() + "'</h1><hr />");
           out.println("<ul>");
           out.println("<li>");
            // loop through these files
            for (int i = 0; i < files.length; i++)
            {
                File f = files[i];
                out.println("  <li>"+getFileInfoContentFor(dir,f,needsDirectoryNameInRelativeAddresses)+"</li>");
            }
            out.println("</ul><hr />");

            out.println("Generated by Simple Web Server");
            out.println("</body></html>");
            return bout.toByteArray();
       }
       catch (Throwable t)
       {
           t.printStackTrace();
           System.err.println("Unable to create directory content");
       }
        return (""+dir.getName()).getBytes();
    }

    /**
     * @param filePath is the path sent from the HTTP request.  
     * The specified file would be within the targetDirectory.
     * @return null if the file doesn't exist.
     */
    private byte[] getFileContents(String filePath)
    {
        return getFileContents(getFileFrom(filePath));
    }

    private File getFileFrom(String filePath)
    {
        return getFileFrom(new File(targetDirectory),filePath);
    }

    private File getFileFrom(File parentDirectory, String filePath)
    { 
        final String separator = System.getProperty("file.separator");
        if (filePath.startsWith(separator))
        {
            filePath = filePath.substring(separator.length());
        }
        File f = new File(parentDirectory + separator + filePath);
        return f;
    }

    private byte[] getFileContents(File parentDirectory, String filePath)
    {
        return getFileContents(getFileFrom(parentDirectory, filePath));
    }

    /**
     * Gets the contents of the specified file.
     * @return null if there is a problem.
     */
    private byte[] getFileContents(File f)
    {
        if (!f.exists())
            return null;
        try
        {
            InputStream in = new FileInputStream(f);
            byte[] data = new byte[(int)f.length()];
            int position = 0;
            while (position < data.length)
            {
              int numBytesRead = in.read(data,position,data.length-position);
              if (numBytesRead < 0)
              {
                  throw new EOFException("Unexpected end of file in '"+f.getAbsolutePath()+"' "
                      +position+" bytes were read in until the end.  "
                      +data.length+" was the expected length.");
              }
              position += numBytesRead;
            }
            return data;
        }
        catch (Throwable t)
        {
            t.printStackTrace();
            System.err.println("Unable to read from requested file: "+f);
        }
        return null;
    }

    private byte[] get404ResponseContents()
    {
        byte[] result = getFileContents("404.html");
        if (result == null)
            return "<html>404 - File not found</html>".getBytes();
        else
            return result;
    }

    /**
     * Gets an appropriate response to a request for the specified file.
     * If the file doesn't exist or can't be read 404 is returned.
     * If the file is a directory, an index page is searched for.  
     * If an index page isn't found, one is automatically generated.
     */
    private HTTPResponse getResponseForFile(String filePath,boolean needsDirectoryNameInRelativeAddresses)
    {
        HTTPResponse response = new HTTPResponse();

        File f = getFileFrom(filePath);
        byte[] contents = null;
        if (f.isDirectory())
        {
            contents = getContentForDirectory(f, needsDirectoryNameInRelativeAddresses);
        }
        else
           contents = getFileContents(f);

        try
        {
            if (contents == null)
            { // file not found or problem reading from file 
                response.setReponseCodeNumber(404);
                contents = get404ResponseContents();
                response.setContent(contents);
                response.setContentType("text/html");
            }
            else
            {
                if (!f.isDirectory())
                   response.setContentType(ContentTypes.guessContentTypeFromPath(filePath));

                response.setContent(contents);
            }
        }
        catch (Throwable t)
        {
            t.printStackTrace();
            System.err.println("Problem generating response to client request for '"+filePath+"'.");
        }
        return response;
    }

    public void handleRequest(HTTPRequest request)
    { 
       /* try to handle the specified request by sending 
        * a response to its socket's output stream
        */
        String filePath = request.getFilePath();

        HTTPResponse response = getResponseForFile(filePath,!request.isForDirectory());

        try
        {
            /**
             * Write the response to the client.
             */
           response.writeTo(request.getSocket().getOutputStream());
        }
        catch (Throwable t)
        {
            t.printStackTrace();
            System.err.println("Unable to properly respond to the client.");
        }
    }

}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
在线免费观看成人短视频| 久久精品国产免费| 99re视频这里只有精品| 国产精品护士白丝一区av| 波多野结衣在线一区| 中文字幕中文在线不卡住| 99精品在线免费| 一区二区国产盗摄色噜噜| 7777精品伊人久久久大香线蕉的 | 国产在线播放一区三区四| 精品国产免费久久| 国产精品1区2区| 中文字幕亚洲不卡| 欧美日韩一级二级三级| 麻豆精品视频在线| 国产精品福利一区二区| 欧美在线播放高清精品| 日本sm残虐另类| 久久久精品免费免费| 91片在线免费观看| 日日欢夜夜爽一区| 亚洲国产精品成人综合色在线婷婷 | 99久久国产综合精品色伊| 亚洲精品少妇30p| 欧美一区中文字幕| 国产成人精品综合在线观看| 亚洲美女在线国产| 日韩视频在线你懂得| 成人永久免费视频| 亚洲sss视频在线视频| 2021中文字幕一区亚洲| 91国偷自产一区二区三区成为亚洲经典 | 日韩一区二区三区av| 成人av网在线| 日本亚洲三级在线| 亚洲欧洲99久久| 日韩精品一区二区三区中文不卡| 95精品视频在线| 久久99国产精品久久99| 亚洲精品ww久久久久久p站| 精品国产sm最大网站免费看| 在线亚洲+欧美+日本专区| 国产精品一区二区男女羞羞无遮挡 | 日韩高清不卡在线| 亚洲视频在线一区| 久久久影视传媒| 精品婷婷伊人一区三区三| av电影天堂一区二区在线| 国内精品久久久久影院一蜜桃| 亚洲女人的天堂| 久久久国产一区二区三区四区小说 | 欧美中文字幕一区| 国产电影一区二区三区| 丝袜亚洲另类丝袜在线| 亚洲欧洲精品一区二区精品久久久| 日韩午夜在线观看视频| 欧美日韩国产色站一区二区三区| 成人av在线网站| 国产一区在线不卡| 免费高清视频精品| 午夜影院久久久| 亚洲久本草在线中文字幕| 久久久99精品免费观看不卡| 日韩一区二区在线免费观看| 欧美最猛黑人xxxxx猛交| 91亚洲国产成人精品一区二区三 | 国产精品99久久久久久有的能看| 日韩激情在线观看| 亚洲午夜成aⅴ人片| 亚洲三级电影全部在线观看高清| 国产亚洲va综合人人澡精品| 自拍视频在线观看一区二区| 精品国产三级电影在线观看| 日韩限制级电影在线观看| 欧美三级三级三级| 欧美三级午夜理伦三级中视频| 91在线porny国产在线看| 不卡的av电影| 99久久精品费精品国产一区二区| 大白屁股一区二区视频| 不卡视频一二三| www.亚洲激情.com| 成人高清免费观看| 成人精品国产一区二区4080| 97久久超碰国产精品| 91欧美一区二区| 91福利视频在线| 欧美群妇大交群的观看方式| 欧美一二三四区在线| 欧美不卡视频一区| 亚洲国产经典视频| 亚洲欧美一区二区三区国产精品| 亚洲激情图片一区| 肉肉av福利一精品导航| 久久国内精品视频| 不卡一区中文字幕| 欧美亚洲尤物久久| 日韩亚洲欧美一区| 久久久久久一二三区| 国产精品免费观看视频| 亚洲最新视频在线播放| 三级成人在线视频| 国产高清成人在线| 色综合咪咪久久| 在线成人av网站| 国产午夜精品福利| 曰韩精品一区二区| 免费国产亚洲视频| 99在线精品一区二区三区| 欧美日韩一区在线观看| 精品99久久久久久| 亚洲老司机在线| 美女一区二区久久| 99r精品视频| 精品剧情v国产在线观看在线| 国产精品婷婷午夜在线观看| 亚洲高清在线精品| 国产成人综合自拍| 在线观看欧美日本| 久久免费美女视频| 香蕉乱码成人久久天堂爱免费| 国产综合色在线视频区| 欧美主播一区二区三区美女| ww亚洲ww在线观看国产| 亚洲影院在线观看| 国产麻豆成人传媒免费观看| 91国产免费观看| 国产欧美一区二区三区鸳鸯浴| 亚洲香蕉伊在人在线观| 国产成人在线视频网址| 欧美色欧美亚洲另类二区| 国产午夜精品久久久久久免费视| 亚洲成年人网站在线观看| 成人av在线网站| 久久综合色播五月| 天堂va蜜桃一区二区三区漫画版| 成人a级免费电影| 337p粉嫩大胆噜噜噜噜噜91av| 一区二区高清视频在线观看| 国产91丝袜在线播放0| 日韩一区二区免费电影| 亚洲一二三四久久| 99久久精品免费看国产| 久久久久久久久久久久久女国产乱 | 久久激五月天综合精品| 欧美撒尿777hd撒尿| 亚洲欧洲日韩综合一区二区| 国产精品一区二区三区99| 日韩精品专区在线影院观看| 亚洲成人动漫av| 日本韩国一区二区| 亚洲日本在线天堂| av不卡免费电影| 国产精品欧美久久久久无广告 | 精品在线观看视频| 91精品国产综合久久精品| 亚洲福利视频一区| 色婷婷av一区二区三区之一色屋| 国产精品人妖ts系列视频| 国产一区999| 久久一区二区视频| 国产一区二区在线观看视频| 6080午夜不卡| 日本网站在线观看一区二区三区| 欧美在线影院一区二区| 亚洲激情男女视频| 色婷婷精品大在线视频| 亚洲精品国产第一综合99久久| 99精品黄色片免费大全| 亚洲欧洲性图库| 色视频欧美一区二区三区| 一区二区三区四区高清精品免费观看 | 欧美色图片你懂的| 亚洲成人中文在线| 91精品国产91久久久久久一区二区 | 日本中文一区二区三区| 777xxx欧美| 久久精品噜噜噜成人av农村| 日韩精品一区二区三区视频播放 | 国产成人精品免费在线| 日本一二三不卡| 91视频在线观看| 一二三区精品视频| 欧美夫妻性生活| 国产在线观看一区二区| 国产精品久线观看视频| 在线观看日韩高清av| 日韩和的一区二区| 久久综合九色综合97婷婷| 成人午夜激情在线| 一区二区三区在线观看国产| 5月丁香婷婷综合| 免费在线观看日韩欧美| 欧美极品美女视频| 在线观看视频一区二区| 麻豆成人久久精品二区三区红 | 日韩区在线观看| 风间由美一区二区av101| 一区二区三区在线观看国产| 在线成人免费视频|