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

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

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

    Rising Sun

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      148 隨筆 :: 0 文章 :: 22 評論 :: 0 Trackbacks
    package MEDET.servlets;
    import java.net.*;
    import java.io.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class SaveFileServlet extends HttpServlet
    {
    ?? FileWriter savefile;
    ?? String filename = null;
    ?? String value = null;
    ?? /**
    ?? * Handles a POST request
    ?? */
    ?? public void doPost(
    ???????? HttpServletRequest request,
    ???????? HttpServletResponse response)
    ????? throws ServletException, IOException
    ?? {
    ????? PrintWriter out = response.getWriter();
    ????? response.setContentType("text/html");
    ????? //FileWriter savefile;
    ????? try {

    ???????? // Verify the content type

    ???????? String ct = request.getContentType();
    ???????? if (!ct.startsWith("multipart/form-data"))
    ??????????? throw new RuntimeException
    ??????????? ("Invalid content type");

    ???????? // Get the boundary string

    ???????? int p = ct.indexOf("boundary=");
    ???????? if (p == -1)
    ??????????? throw new RuntimeException
    ??????????? ("No boundary string found");

    ???????? p += "boundary=".length();
    ???????? String boundary = "--" + ct.substring(p);
    ???????? String finalBoundary = boundary + "--";

    ???????? // We'll parse the multipart/form-data
    ???????? // with a finite state machine

    ???????? // Define names for the parser states

    ???????? final int INIT = 0;
    ???????? final int READING_HEADERS = 1;
    ???????? final int READING_DATA = 2;

    ???????? int state = INIT;

    ???????? // Read and extract the fields

    ???????? BufferedReader in = request.getReader();
    ???????? main: for (;;) {
    ??????????? String line = in.readLine();
    ??????????? if (line == null)
    ?????????????? break;

    ??????????? switch (state) {

    ?????????????? // State 0: Ignoring everything before
    ?????????????? // the first boundary

    ?????????????? case INIT:
    ????????????????? if (line.startsWith(finalBoundary))
    ???????????????????? break main;
    ????????????????? if (line.startsWith(boundary)) {
    ???????????????????? state = READING_HEADERS;
    ???????????????????? filename = "";
    ???????????????????? value = "";
    ????????????????? }
    ????????????????? break;

    ?????????????? // State 1: Parsing the headers

    ?????????????? case READING_HEADERS:
    ????????????????? if (line.length() == 0)
    ???????????????????? state = READING_DATA;
    ????????????????? else {

    ???????????????????? // Get the field name

    ???????????????????? p = line.indexOf("filename=\"");
    ???????????????????? if (p == -1)
    ??????????????????????? break;
    ???????????????????? p += "filename=\"".length();

    ???????????????????? // ... up to the closing quote.

    ???????????????????? int q = line.indexOf("\"", p);
    ???????????????????? if (q == -1)
    ??????????????????????? break;
    ???????????????????? filename = line.substring(p, q);
    ???????????????????? filename="./config/medet/applications/DefaultWebApp/"+filename.substring(filename.lastIndexOf("\\")+1);
    ???????????????????? savefile=new FileWriter(filename);
    ???????????????????? value = "";
    ????????????????? }
    ????????????????? break;

    ?????????????? // State 2: Reading the data

    ?????????????? case READING_DATA:
    ????????????????? if (line.startsWith(finalBoundary)) {
    ???????????????????? savefile.write(value);
    ???????????????????? savefile.close();
    ???????????????????? break main;
    ????????????????? }
    ????????????????? if (line.startsWith(boundary)) {
    ???????????????????? state = READING_HEADERS;
    ????????????????? }
    ????????????????? else {
    ???????????????????? if (value.length() > 0)
    ??????????????????????? value += "\n";
    ???????????????????? value += line;
    ????????????????? }
    ????????????????? break;
    ??????????? }

    ???????? }
    ???????? // Report the incident number back to the client
    ???????? String[] text = {
    ??????????? "<HTML>",
    ??????????? "<HEAD>",
    ??????????? "<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>",
    ??????????? "<TITLE>文件上傳成功</TITLE>",
    ??????????? "</HEAD>",
    ??????????? "<BODY>",
    ??????????? "<CENTER>",
    ??????????? "<H3>文件上傳成功!</H3>",
    ??????????? "</CENTER>"
    ???????? };
    ???????? for (int i = 0; i < text.length; i++)
    ??????????? out.println(text[i]);
    ??????????? out.println(filename);
    ??????????? out.println("</BODY>");
    ??????????? out.println("</HTML>");
    ????? }

    ????? catch (Exception e) {
    ???????? // Write the exception message
    ???????? out.println("<H3>Error:</H3>");
    ???????? out.println("<PRE>");
    ???????? out.println(e.getMessage());
    ???????? out.println("</PRE>");
    ????? }
    ????? finally {
    ???????? out.flush();
    ????? }
    ?? }
    }
    posted on 2006-07-13 15:01 brock 閱讀(917) 評論(0)  編輯  收藏

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


    網站導航:
     
    主站蜘蛛池模板: 亚洲成熟xxxxx电影| 日本免费福利视频| 中国好声音第二季免费播放| 特黄特色的大片观看免费视频| 美女被羞羞网站免费下载| 在线视频网址免费播放| AV无码免费永久在线观看| 国产午夜鲁丝片AV无码免费| 亚洲ⅴ国产v天堂a无码二区| a级毛片免费播放| 日本v片免费一区二区三区| 亚洲综合国产成人丁香五月激情| 色偷偷亚洲男人天堂| 久久久国产精品无码免费专区| 国产一级高青免费| 国产aⅴ无码专区亚洲av| 亚洲欧美日韩国产成人| 日韩插啊免费视频在线观看| 大香人蕉免费视频75| 久久久久一级精品亚洲国产成人综合AV区| 久久久久亚洲AV无码麻豆| 日本一区二区三区在线视频观看免费 | 国产免费131美女视频| 一级毛片不卡免费看老司机| 好大好硬好爽免费视频| 另类专区另类专区亚洲| 免费观看黄网站在线播放| 国产亚洲美女精品久久久久狼| 亚洲国产精品自在自线观看| 99re6在线精品视频免费播放 | 亚洲精品国精品久久99热一| 毛片无码免费无码播放| 亚洲字幕AV一区二区三区四区| 亚洲 自拍 另类小说综合图区| 国产成人精品日本亚洲网址| 免费观看一区二区三区| 久久久久亚洲?V成人无码| 无码少妇精品一区二区免费动态| 亚洲精品456人成在线| 免费观看激色视频网站(性色) | 亚洲精品熟女国产|