Ⅰ 得到file的文件名和存儲路徑後,在Struts2中的action中要怎樣獲取file的內容並顯示到action轉到的jsp頁面中
struts2單文件上傳:
首先是一個文件上傳頁面,這個比較簡單,就是一個表單,裡面有個文件上傳框
<!--在進行文件上傳時,表單提交方式一定要是post的方式,因為文件上傳時二進制文件可能會很大,還有就是enctype屬性,這個屬性一定要寫成multipart/form-data,
不然就會以二進制文本上傳到伺服器端-->
<form action="fileUpload.action" method="post" enctype="multipart/form-data">
username: <input type="text" name="username"><br>
file: <input type="file" name="file"><br>
<input type="submit" value="submit">
</form>
接下來是FileUploadAction部分代碼,因為struts2對上傳和下載都提供了很好的實習機制,所以在action這段我們只需要寫很少的代碼就行:
public class FileUploadAction extends ActionSupport
{
private String username;
//注意,file並不是指前端jsp上傳過來的文件本身,而是文件上傳過來存放在臨時文件夾下面的文件
private File file;
//提交過來的file的名字
private String fileFileName;
//提交過來的file的MIME類型
private String fileContentType;
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
public File getFile()
{
return file;
}
public void setFile(File file)
{
this.file = file;
}
public String getFileFileName()
{
return fileFileName;
}
public void setFileFileName(String fileFileName)
{
this.fileFileName = fileFileName;
}
public String getFileContentType()
{
return fileContentType;
}
public void setFileContentType(String fileContentType)
{
this.fileContentType = fileContentType;
}
@Override
public String execute() throws Exception
{
String root = ServletActionContext.getServletContext().getRealPath("/upload");
InputStream is = new FileInputStream(file);
OutputStream os = new FileOutputStream(new File(root, fileFileName));
System.out.println("fileFileName: " + fileFileName);
// 因為file是存放在臨時文件夾的文件,我們可以將其文件名和文件路徑列印出來,看和之前的fileFileName是否相同
System.out.println("file: " + file.getName());
System.out.println("file: " + file.getPath());
byte[] buffer = new byte[500];
int length = 0;
while(-1 != (length = is.read(buffer, 0, buffer.length)))
{
os.write(buffer);
}
os.close();
is.close();
return SUCCESS;
}
}
首先我們要清楚一點,這里的file並不是真正指代jsp上傳過來的文件,當文件上傳過來時,struts2首先會尋找struts.multipart.saveDir(這個是在default.properties裡面有)這個name所指定的存放位置,我們可以新建一個struts.properties屬性文件來指定這個臨時文件存放位置,如果沒有指定,那麼文件會存放在tomcat的apache-tomcat-7.0.29\work\Catalina\localhost\目錄下,然後我們可以指定文件上傳後的存放位置,通過輸出流將其寫到流裡面就行了,這時我們就可以在文件夾里看到我們上傳的文件了。
文件上傳後我們還需要將其下載下來,其實struts2的文件下載原理很簡單,就是定義一個輸入流,然後將文件寫到輸入流裡面就行,關鍵配置還是在struts.xml這個配置文件里配置:
FileDownloadAction代碼如下:
public class FileDownloadAction extends ActionSupport
{
public InputStream getDownloadFile()
{
return ServletActionContext.getServletContext().getResourceAsStream("upload/通訊錄2012年9月4日.xls");
}
@Override
public String execute() throws Exception
{
return SUCCESS;
}
}
我們看,這個action只是定義了一個輸入流,然後為其提供getter方法就行,接下來我們看看struts.xml的配置文件:
<action name="fileDownload" class="com.xiaoluo.struts2.FileDownloadAction">
<result name="success" type="stream">
<param name="contentDisposition">attachment;filename="通訊錄2012年9月4日.xls"</param>
<param name="inputName">downloadFile</param>
</result>
</action>
struts.xml配置文件有幾個地方我們要注意,首先是result的類型,以前我們定義一個action,result那裡我們基本上都不寫type屬性,因為其默認是請求轉發(dispatcher)的方式,除了這個屬性一般還有redirect(重定向)等這些值,在這里因為我們用的是文件下載,所以type一定要定義成stream類型,告訴action這是文件下載的result,result元素裡面一般還有param子元素,這個是用來設定文件下載時的參數,inputName這個屬性就是得到action中的文件輸入流,名字一定要和action中的輸入流屬性名字相同,然後就是contentDisposition屬性,這個屬性一般用來指定我們希望通過怎麼樣的方式來處理下載的文件,如果值是attachment,則會彈出一個下載框,讓用戶選擇是否下載,如果不設定這個值,那麼瀏覽器會首先查看自己能否打開下載的文件,如果能,就會直接打開所下載的文件,(這當然不是我們所需要的),另外一個值就是filename這個就是文件在下載時所提示的文件下載名字。在配置完這些信息後,我們就能過實現文件的下載功能了。
struts2多文件上傳:
其實多文件上傳和單文件上傳原理一樣,單文件上傳過去的是單一的File,多文件上傳過去的就是一個List<File>集合或者是一個File[]數組,首先我們來看一下前端jsp部分的代碼,這里我用到了jquery來實現動態的添加文件下載框以及動態的刪除下載框:
<script type="text/javascript" src="script/jquery-1.8.1.js"></script>
<script type="text/javascript">
$(function()
{
$("#button").click(function()
{
var html = $("<input type='file' name='file'>");
var button = $("<input type='button' name='button' value='刪除'><br>");
$("#body div").append(html).append(button);
button.click(function()
{
html.remove();
button.remove();
})
})
})
</script>
</head>
<body id="body">
<form action="fileUpload2.action" method="post" enctype="multipart/form-data">
username: <input type="text" name="username"><br>
file: <input type="file" name="file">
<input type="button" value="添加" id="button"><br>
<div></div>
<input type="submit" value="submit">
</form>
</body>
file的名字必須都命名成file才行,然後處理多文件上傳的action代碼如下:
public class FileUploadAction2 extends ActionSupport
{
private String username;
//這里用List來存放上傳過來的文件,file同樣指的是臨時文件夾中的臨時文件,而不是真正上傳過來的文件
private List<File> file;
//這個List存放的是文件的名字,和List<File>中的文件相對應
private List<String> fileFileName;
private List<String> fileContentType;
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
public List<File> getFile()
{
return file;
}
public void setFile(List<File> file)
{
this.file = file;
}
public List<String> getFileFileName()
{
return fileFileName;
}
public void setFileFileName(List<String> fileFileName)
{
this.fileFileName = fileFileName;
}
public List<String> getFileContentType()
{
return fileContentType;
}
public void setFileContentType(List<String> fileContentType)
{
this.fileContentType = fileContentType;
}
@Override
public String execute() throws Exception
{
String root = ServletActionContext.getServletContext().getRealPath("/upload");
for(int i = 0; i < file.size(); i++)
{
InputStream is = new FileInputStream(file.get(i));
OutputStream os = new FileOutputStream(new File(root, fileFileName.get(i)));
byte[] buffer = new byte[500];
@SuppressWarnings("unused")
int length = 0;
while(-1 != (length = is.read(buffer, 0, buffer.length)))
{
os.write(buffer);
}
os.close();
is.close();
}
return SUCCESS;
}
}
這樣同樣將其寫到一個輸出流裡面,這樣我們就可以在文件夾里看到上傳的多個文件了
Ⅱ struts2 上傳文件得到的是.tmp 怎麼得到原有文件名
我上傳的文件還沒有出現過類似問題,用的是第三方類庫fileupload上傳的!
Ⅲ struts2上傳文件的類型去哪裡找
struts2是根據contentType來限制的,並不是文件的擴展名
比如我想僅上傳image/png,image/gif,image/jpeg這三種文件類型
第一種方法是通過javascript校驗來限制,這個比較簡單,獲取input的value然後截取擴展名進行判斷即可
第二種是根據struts2自帶的fileupload攔截器中提供的allowedTypes來進行限制,步驟如下:
1 配置fileupload攔截器
struts2的defaultStack中已經含有fileupload攔截器,如果想加入allowedTypes參數,需要從新寫一個defaultstack ,拷貝過來修改一下即可:
<interceptor-stack name="myDefaultStack">
<interceptor-ref name="exception"/>
<interceptor-ref name="alias"/>
<interceptor-ref name="servletConfig"/>
<interceptor-ref name="i18n"/>
<interceptor-ref name="prepare"/>
<interceptor-ref name="chain"/>
<interceptor-ref name="debugging"/>
<interceptor-ref name="profiling"/>
<interceptor-ref name="scopedModelDriven"/>
<interceptor-ref name="modelDriven"/>
<interceptor-ref name="fileUpload">
<param name="allowedTypes">
image/png,image/gif,image/jpeg
</param>
</interceptor-ref>
<interceptor-ref name="checkbox"/>
<interceptor-ref name="staticParams"/>
<interceptor-ref name="actionMappingParams"/>
<interceptor-ref name="params">
<param name="excludeParams">dojo\..*,^struts\..*</param>
</interceptor-ref>
<interceptor-ref name="conversionError"/>
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
<interceptor-ref name="workflow">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="myDefaultStack"></default-interceptor-ref>
僅修改代碼中的
<interceptor-ref name="fileUpload">
<param name="allowedTypes">
image/png,image/gif,image/jpeg
</param>
</interceptor-ref>
上面配置的是上傳文件類型的限制,其實共有兩個參數
maximumSize (可選) - 這個攔截器允許的上傳到action中的文件最大長度(以byte為單位). 注意這個參數和在webwork.properties中定義的屬性沒有關系,默認2MB
allowedTypes (可選) - 以逗號分割的contentType類型列表(例如text/html),這些列表是這個攔截器允許的可以傳到action中的contentType.如果沒有指定就是允許任何上傳類型.
2 jsp頁面定義如下(testFileUpload.jsp)
<s:form action="testFileUpload" method="post" enctype="multipart/form-data">
<s:file name="file"theme="simple"/>
<s:fielderror name="file"></s:fielderror>
<s:submit/>
</s:form>
3 後台的action聲明如下(我用的是struts2的註解進行action配置)
public class TestFileUploadAction extends ActionSupport{
private File file;
private String fileContentType;
private String fileFileName;
@Action(
value = "testFileUpload", results = {
@Result(name = "input", location = "/testFileUpload.jsp"),
@Result(name = "success", location = "/testFileUploadSuccess.jsp")
}
)
public String execute() {
return SUCCESS;
}
get/set......
}
注意:如果jsp中file的name="xxx",那麼後台action中的屬性要做相應更改為
private File xxx;
private String xxxContentType;
private String xxxFileName;
同時注意大小寫一定要一致
4 定義錯誤文件類型的消息提示,這個需要用到struts2的資源文件,在struts.properties文件中加入
struts.custom.i18n.resources=globalMessages
globalMessages對應著資源文件名
5 在源文件夾下定義資源文件globalMessages.properties,並在裡面加入如下信息:
struts.messages.error.content.type.not.allowed=upload file contenttype is invalidate
這里稍作說明(拷貝一下struts2的幫助):
如果你的action實現了ValidationAware介面(如果action繼承了ActionSupport,那麼就相當於實現了ValidationAware),這個攔截器就可以添加幾種欄位錯誤.這些錯誤信息是基於存儲在struts-messages.properties文件中的一些i18n值,這個文件是所有i18n請求的默認文件.你可以在自己消息文件的復寫以下key的消息文字
struts.messages.error.uploading - 文件不能上傳的通用錯誤信息
struts.messages.error.file.too.large - 上傳文件長度過大的錯誤信息
struts.messages.error.content.type.not.allowed - 當上傳文件不符合指定的contentType
以上配置完畢後,測試一下,對於非法的contentType,例如xxx.log這個文件的的contentType是pplication/octet-stream
會給出提示:upload file contenttype is invalidate
'.a' : 'application/octet-stream',
'.ai' : 'application/postscript',
'.aif' : 'audio/x-aiff',
'.aifc' : 'audio/x-aiff',
'.aiff' : 'audio/x-aiff',
'.au' : 'audio/basic',
'.avi' : 'video/x-msvideo',
'.bat' : 'text/plain',
'.bcpio' : 'application/x-bcpio',
'.bin' : 'application/octet-stream',
'.bmp' : 'image/x-ms-bmp',
'.c' : 'text/plain',
'.cdf' : 'application/x-cdf',
'.cdf' : 'application/x-netcdf',
'.cpio' : 'application/x-cpio',
'.csh' : 'application/x-csh',
'.css' : 'text/css',
'.dll' : 'application/octet-stream',
'.doc' : 'application/msword',
'.dot' : 'application/msword',
'.dvi' : 'application/x-dvi',
'.eml' : 'message/rfc822',
'.eps' : 'application/postscript',
'.etx' : 'text/x-setext',
'.exe' : 'application/octet-stream',
'.gif' : 'image/gif',
'.gtar' : 'application/x-gtar',
'.h' : 'text/plain',
'.hdf' : 'application/x-hdf',
'.htm' : 'text/html',
'.html' : 'text/html',
'.ief' : 'image/ief',
'.jpe' : 'image/jpeg',
'.jpeg' : 'image/jpeg',
'.jpg' : 'image/jpeg',
'.js' : 'application/x-javascript',
'.ksh' : 'text/plain',
'.latex' : 'application/x-latex',
'.m1v' : 'video/mpeg',
'.man' : 'application/x-troff-man',
'.me' : 'application/x-troff-me',
'.mht' : 'message/rfc822',
'.mhtml' : 'message/rfc822',
'.mif' : 'application/x-mif',
'.mov' : 'video/quicktime',
'.movie' : 'video/x-sgi-movie',
'.mp2' : 'audio/mpeg',
'.mp3' : 'audio/mpeg',
'.mpa' : 'video/mpeg',
'.mpe' : 'video/mpeg',
'.mpeg' : 'video/mpeg',
'.mpg' : 'video/mpeg',
'.ms' : 'application/x-troff-ms',
'.nc' : 'application/x-netcdf',
'.nws' : 'message/rfc822',
'.o' : 'application/octet-stream',
'.obj' : 'application/octet-stream',
'.oda' : 'application/oda',
'.p12' : 'application/x-pkcs12',
'.p7c' : 'application/pkcs7-mime',
'.pbm' : 'image/x-portable-bitmap',
'.pdf' : 'application/pdf',
'.pfx' : 'application/x-pkcs12',
'.pgm' : 'image/x-portable-graymap',
'.pl' : 'text/plain',
'.png' : 'image/png',
'.pnm' : 'image/x-portable-anymap',
'.pot' : 'application/vnd.ms-powerpoint',
'.ppa' : 'application/vnd.ms-powerpoint',
'.ppm' : 'image/x-portable-pixmap',
'.pps' : 'application/vnd.ms-powerpoint',
'.ppt' : 'application/vnd.ms-powerpoint',
'.ps' : 'application/postscript',
'.pwz' : 'application/vnd.ms-powerpoint',
'.py' : 'text/x-python',
'.pyc' : 'application/x-python-code',
'.pyo' : 'application/x-python-code',
'.qt' : 'video/quicktime',
'.ra' : 'audio/x-pn-realaudio',
'.ram' : 'application/x-pn-realaudio',
'.ras' : 'image/x-cmu-raster',
'.rdf' : 'application/xml',
'.rgb' : 'image/x-rgb',
'.roff' : 'application/x-troff',
'.rtx' : 'text/richtext',
'.sgm' : 'text/x-sgml',
'.sgml' : 'text/x-sgml',
'.sh' : 'application/x-sh',
'.shar' : 'application/x-shar',
'.snd' : 'audio/basic',
'.so' : 'application/octet-stream',
'.src' : 'application/x-wais-source',
'.sv4cpio': 'application/x-sv4cpio',
'.sv4crc' : 'application/x-sv4crc',
'.swf' : 'application/x-shockwave-flash',
'.t' : 'application/x-troff',
'.tar' : 'application/x-tar',
'.tcl' : 'application/x-tcl',
'.tex' : 'application/x-tex',
'.texi' : 'application/x-texinfo',
'.texinfo': 'application/x-texinfo',
'.tif' : 'image/tiff',
'.tiff' : 'image/tiff',
'.tr' : 'application/x-troff',
'.tsv' : 'text/tab-separated-values',
'.txt' : 'text/plain',
'.ustar' : 'application/x-ustar',
'.vcf' : 'text/x-vcard',
'.wav' : 'audio/x-wav',
'.wiz' : 'application/msword',
'.wsdl' : 'application/xml',
'.xbm' : 'image/x-xbitmap',
'.xlb' : 'application/vnd.ms-excel',
'.xls' : 'application/excel',
'.xls' : 'application/vnd.ms-excel',
'.xml' : 'text/xml',
'.xpdl' : 'application/xml',
'.xpm' : 'image/x-xpixmap',
'.xsl' : 'application/xml',
'.xwd' : 'image/x-xwindowmp',
'.zip' : 'application/zip',
Ⅳ java struts2 怎麼獲取從jsp傳過來的多個file
在action中聲明三個變數,然年後生成get、set方法
privateFilefile;
privateStringfileFileName;
privateStringfileContentType;
注意,這三個變數的名字不能亂寫,必須是這個格式的。如果你在表單的名字叫image,那個變數名字就應該是:
privateFileimage;
privateStringimageFileName;
privateStringimageContentType;
/**************************華麗的分割線**************************************/
第一個就是葯品上傳的文件的引用,第二個是要上傳文件的名字,是三個是要上傳文件的類型。
然後就可以通過輸出流進行上傳了。
Ⅳ 為什麼Struts2上傳文件之後擴展名變成了tmp,如何取得文件正確的擴展名
在action中獲取到上傳文件名利用上傳文件名來存儲就不會出現tmp結尾文件了
Ⅵ Struts2怎麼獲取到 上傳文件的源路徑
必要前提:
a.表單method必須是post;
b.enctype取值必須是multipart/form-data;
c.提供文件選擇域。定義參數接收
File photo; // 接受上傳的文件 File接受
String photoFileName; // 上傳的文件名 文件name屬性+FileName,
String photoContentType; // 文件的MIME類型 文件name屬性+ContentType
例如:
action中
Ⅶ 用Struts2做文件上傳時,前台js獲得文件對象,文件名,文件內容類型。怎麼在action中獲得文件對象
從視圖層傳入action的所有對象都封裝在mapper對象中。。。
Ⅷ struts2.0怎麼實現上傳文件
一、創建jsp頁面:
注意!要上傳文件,表單必須添加 enctype 屬性,如下: enctype="multipart/form-data"
index.jsp 代碼如下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<!-- 注意!表單必須添加 enctype 屬性,值為"multipart/form-data" -->
<form action="upload.action" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" value="上傳"/>
</form>
</body>
</html>
二、創建Action類:
1. 添加三個私有欄位,並添加相應的get,set方法。
private File file; ——上傳的文件,變數名對應頁面上"file"input的name屬性值。類型為java.io.File
private String fileContentType;——上傳文件的格式類型名,變數名格式為:頁面上"file"input的name屬性值+ContentType
private String fileFileName——上傳的文件名,變數名格式為:頁面上"file"input的name屬性值+fileFileName。
2. 使用struts2提供的FileUtils類拷貝進行文件的拷貝。FileUtils類位於org.apache.commons.io包下。
3. 在項目目錄下的WebContent目錄下添加 upload 文件夾,用於存放客戶端上傳過來的文件,對應第15行代碼。
Upload.java代碼如下:
1 import java.io.File;
2 import java.io.IOException;
3 import org.apache.commons.io.FileUtils;
4 import org.apache.struts2.ServletActionContext;
5 import com.opensymphony.xwork2.ActionSupport;
6
7 public class Upload extends ActionSupport{
8 private File file;
9 private String fileContentType;
10 private String fileFileName;
11
12 @Override
13 public String execute() throws Exception {
14 //得到上傳文件在伺服器的路徑加文件名
15 String target=ServletActionContext.getServletContext().getRealPath("/upload/"+fileFileName);
16 //獲得上傳的文件
17 File targetFile=new File(target);
18 //通過struts2提供的FileUtils類拷貝
19 try {
20 FileUtils.File(file, targetFile);
21 } catch (IOException e) {
22 e.printStackTrace();
23 }
24 return SUCCESS;
25 }
26
27 //省略get,set方法...........
28
29 }
三、在struts.xml中添加相應的配置代碼。
struts.xml代碼如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="default" namespace="/" extends="struts-default">
<action name="upload" class="Upload">
<result>index.jsp</result>
</action>
</package>
</struts>
四、測試。
啟動伺服器,進入index頁面。
選擇一改圖片,點擊上傳提交表單。
打開upload文件夾(注意,這里指的是web伺服器下的目錄,如我用的web伺服器是tomcat安裝在電腦D盤,項目名稱為「Struts2Upload」那麼其路徑為:D:\apache-tomcat-7.0.40\webapps\Struts2Upload\upload)可以看到剛才選中的圖片已經上傳到該目錄下了。
上傳多個文件
一、修改頁面文件
增加繼續添加按鈕和 addfile() 方法,讓頁面可以通過javascript增加 input 標簽。
修改後的 index.jsp代碼如下:
1 <%@ page language="java" contentType="text/html; charset=UTF-8"
2 pageEncoding="UTF-8"%>
3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4 <html>
5 <head>
6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
7 <script type="text/javascript">
8 //添加javascript方法 addfile() 在頁面中境加input標簽、
9 function addfile(){
10 var file = document.createElement("input");
11 file.type="file";
12 file.name="file";
13 document.getElementById("fileList").appendChild(file);
14 document.getElementById("fileList").appendChild(document.createElement("br"));
15 }
16 </script>
17 <title>Insert title here</title>
18 </head>
19 <body>
20 <!-- 注意!表單必須添加 enctype 屬性,值為"multipart/form-data" -->
21 <form action="upload.action" method="post" enctype="multipart/form-data">
22 <div id="fileList">
23 <input type="file" name="file" /><br/>
24 </div>
25 <!-- 添加繼續添加按鈕,點擊按鈕調用addfile() -->
26 <input type="button" value="繼續添加" onclick="addfile()" />
27 <input type="submit" value="上傳"/>
28 </form>
29 </body>
30 </html>
二、修改Action類
1. 把三個私有欄位(file,fileContentType,fileFileName)的類型更改為數組或集合類型。並添加相應的get,set方法。
2. 通過循環來上傳多個文件。
修改後的Upload.java代碼如下:
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class Upload extends ActionSupport{
//把這三個欄位類型更改為數組或集合
private File[] file;
private String[] fileContentType;
private String[] fileFileName;
@Override
public String execute() throws Exception {
//通過循環來上傳多個文件
for(int i=0;i<file.length;i++){
//得到上傳文件在伺服器的路徑加文件名
String target=ServletActionContext.getServletContext().getRealPath("/upload/"+fileFileName[i]);
//獲得上傳的文件
File targetFile=new File(target);
//通過struts2提供的FileUtils類拷貝
try {
FileUtils.File(file[i], targetFile);
} catch (IOException e) {
e.printStackTrace();
}
}
return SUCCESS;
}
//省略set,get方法...................
}
三、測試
1. 啟動伺服器,打開index.jsp頁面。點擊繼續添加,添加兩個input。同時上傳三張圖片。
2. 點擊上傳提交表單。打開upload文件夾,可以看到剛才選中的三張圖片已經上傳到該目錄下了。
參考資料http://www.cnblogs.com/likailan/p/3330465.html
Ⅸ struts2上傳文件的時候,為什麼我獲取不到上傳文件的名稱
檢查幾個地方:
1、上傳控制項的name和後台對應的屬性名是否一致。
2、是否加入fileupload攔截器。
3、文件是否過大和不符合後綴名。