檔案上傳(JSP Servlet)

2021-09-12 05:59:46 字數 1579 閱讀 1788

一、jsp + servlet 實現簡單的檔案上傳:

1、使用的jar包:commmons-fileupload.jar

2、jsp頁面:enctype="multipart/form-data"

<%@page pageencoding="utf-8" contenttype="text/html; charset=utf-8"%>

<%

string path = request.getcontextpath();

string basepath = request.getscheme()+"://"+request.getservername()+":"+request.getserverport()+path+"/";

%>

2、servlet實現:

}}3、web.xml配置:

fileupload

test.upload

/upload

二、jsp + struts1實現檔案上傳:

1、form表單:

public class uploadfileform extends actionform

public void setformfile(formfile uploadfile)

}

2、 action:

public class uploadaction extends action

}}

3、jsp:file的name屬性與form表單中formfile名稱對應。

4、web.xml:actionservelet的配置

5、struts-config.xml:action配置

三、jsp + struts2實現檔案上傳

action實現:

public class uploadaction extends actionsupport 

public void setupload(file upload)

public string getuploadfilename()

public void setuploadfilename(string uploadfilename)

public string upload() throws ioexception

}}

關於檔案上傳中文亂碼的問題:struts從request裡利用beanutils.populate()把值賦給form的時候已經是亂碼的,所以賦值之前要進行編碼的轉換。可以通過寫過濾器進行編碼的設定。

jsp servlet檔案上傳

一 檔案上傳的基本操作 multipart form data和 的區別 form元素的 enctype 屬性指定了表單資料向伺服器提交時所採用的編碼型別,預設的預設值是。然而,在向伺服器傳送大量的文字 包含非ascii 字元的文字或二進位制資料時這種編碼方式效率很低。在檔案上載時,所使用的編碼型別...

php mysql上傳檔案 PHP 檔案上傳

通過 php,可以把檔案上傳到伺服器。建立乙個檔案上傳表單 允許使用者從表單上傳檔案是非常有用的。請看下面這個供上傳檔案的 html 表單 芝麻教程 web3.xin 檔名 將以上 儲存到 form.html 檔案中。有關上面的 html 表單的一些注意項列舉如下 標籤的 enctype 屬性規定了...

檔案上傳和多檔案上傳

上傳檔案分析 上傳的檔案是以二進位制的形式上傳,因此在上傳表單裡面需要宣告enctype multipart form data 上傳的檔案所有的資訊都包含到全域性變數 files中 如 問題 1 上傳中文亂碼問題 只需使用函式incov 原來的編碼utf 8 轉化為的編碼gbk gb2312 檔名...