日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java不用插件播放媒体文件_java servlet不用插件上传文件:

發布時間:2023/12/10 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java不用插件播放媒体文件_java servlet不用插件上传文件: 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

展開全部

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 = {

" ",

"

",

" ",

"

文件32313133353236313431303231363533e58685e5aeb931333262373264上傳成功 ",

" ",

"

",

"

",

"

文件上傳成功!

",

"

"

};

for (int i = 0; i < text.length; i++)

out.println(text[i]);

out.println(filename);

out.println( " ");

out.println( " ");

}

catch (Exception e) {

// Write the exception message

out.println( "

Error:

");

out.println( "

");

out.println(e.getMessage());

out.println( "

");

}

finally {

out.flush();

}

}

}

希望幫到你

本回答由網友推薦

已贊過

已踩過<

你對這個回答的評價是?

評論

收起

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的java不用插件播放媒体文件_java servlet不用插件上传文件:的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。