- 浏览: 96683 次
- 性别:
- 来自: 临沂
文章分类
- 全部博客 (125)
- spring (2)
- java (6)
- jquery (0)
- android (0)
- window (1)
- 数据库 (0)
- 项目管理 (1)
- maven (0)
- english (0)
- ext (0)
- javascript and html (2)
- hibernate (1)
- p6spy (0)
- shiro (0)
- fusionchart (0)
- FileUtils (0)
- struts2 (0)
- ireport (0)
- webservice (0)
- stripes (0)
- jsp (1)
- it综合 (1)
- linux (1)
- 工作流 (0)
- activiti (0)
- poi (0)
- nosql (0)
- mongodb (0)
- lucene (0)
- nodejs (10)
- eclipse (2)
- objective-c (1)
最新评论
.struts2上传文件
struts2上传文件
java 2011-03-11 23:00:50 阅读18 评论0 字号:大中小订阅
Java代码
<%@pagecontentType="text/html;charset=UTF-8"%>
<%@taglibprefix="s"uri="/struts-tags"%>
<html>
<head>
<title>Struts2FileUpload</title>
</head>
<body>
<s:textname=""></s:text>
<formaction="fileUpload.action"method="POST"enctype="multipart/form-data">
文件标题:<inputtype="text"name="title"size="50"/><br/>
选择文件:<inputtype="file"name="upload"size="50"/><br/>
选择文件:<inputtype="file"name="upload"size="50"/><br/>
选择文件:<inputtype="file"name="upload"size="50"/><br/>
<inputtype="submit"value="上传"/>
</form>
</body>
</html>
<%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> <title>Struts2 File Upload</title> </head> <body> <s:text name=""></s:text> <form action="fileUpload.action" method="POST" enctype="multipart/form-data"> 文件标题:<input type="text" name="title" size="50"/><br/> 选择文件:<input type="file" name="upload" size="50"/><br/> 选择文件:<input type="file" name="upload" size="50"/><br/> 选择文件:<input type="file" name="upload" size="50"/><br/> <input type="submit" value=" 上传 "/> </form> </body> </html>
baseAction文件
Java代码
//pizza
packagecom.trendcom.upload.action;
importjavax.servlet.ServletContext;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
importjavax.servlet.http.HttpSession;
importorg.apache.struts2.ServletActionContext;
importcom.opensymphony.xwork2.ActionSupport;
publicclassBaseActionextendsActionSupport{
publicHttpServletRequestgetRequest(){
returnServletActionContext.getRequest();
}
publicHttpServletResponsegetResponse(){
returnServletActionContext.getResponse();
}
publicHttpSessiongetSession(){
returngetRequest().getSession();
}
publicServletContextgetServletContext(){
returnServletActionContext.getServletContext();
}
publicStringgetRealyPath(Stringpath){
returngetServletContext().getRealPath(path);
}
}
//pizza
package com.trendcom.upload.action;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class BaseAction extends ActionSupport {
public HttpServletRequest getRequest(){
return ServletActionContext.getRequest();
}
public HttpServletResponse getResponse(){
return ServletActionContext.getResponse();
}
public HttpSession getSession(){
return getRequest().getSession();
}
public ServletContext getServletContext(){
return ServletActionContext.getServletContext();
}
public String getRealyPath(String path){
return getServletContext().getRealPath(path);
}
}
action文件
Java代码
packagecom.trendcom.upload.action;
importjava.io.BufferedInputStream;
importjava.io.BufferedOutputStream;
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.FileOutputStream;
importjava.io.IOException;
importjava.io.InputStream;
importjava.io.OutputStream;
importjava.util.ArrayList;
importjava.util.List;
publicclassUploadFileActionextendsBaseAction{
privatestaticfinalintBUFFER_SIZE=16*1024;
//文件标题
privateStringtitle;
//用File数组来封装多个上传文件域对象
privateFile[]upload;
//用String数组来封装多个上传文件名
privateString[]uploadFileName;
//用String数组来封装多个上传文件类型
privateString[]uploadContentType;
//保存文件的目录路径(通过依赖注入)
privateStringsavePath;
//以下为所有属性的getter和setter。省略。。。
//自己封装的一个把源文件对象复制成目标文件对象
privatestaticbooleancopy(Filesrc,Filedst){
booleanresult=false;
InputStreamin=null;
OutputStreamout=null;
try{
in=newBufferedInputStream(newFileInputStream(src),BUFFER_SIZE);
out=newBufferedOutputStream(newFileOutputStream(dst),
BUFFER_SIZE);
byte[]buffer=newbyte[BUFFER_SIZE];
intlen=0;
while((len=in.read(buffer))>0){
out.write(buffer,0,len);
}
result=true;
}catch(Exceptione){
e.printStackTrace();
result=false;
}finally{
if(null!=in){
try{
in.close();
}catch(IOExceptione){
e.printStackTrace();
}
}
if(null!=out){
try{
out.close();
}catch(IOExceptione){
e.printStackTrace();
}
}
}
returnresult;
}
@Override
publicStringexecute()throwsException{
File[]srcFiles=this.getUpload();
List<String>successFileList=newArrayList<String>();
//处理每个要上传的文件
for(inti=0;i<srcFiles.length;i++){
//根据服务器的文件保存地址和原文件名创建目录文件全路径
StringdstPath=getRealyPath(getSavePath())
+"//"+this.getUploadFileName()[i];
FiledstFile=newFile(dstPath);
if(copy(srcFiles[i],dstFile)){
successFileList.add(getUploadFileName()[i]);
}
}
getRequest().setAttribute("successFileList",successFileList);
returnSUCCESS;
}
publicStringgetTitle(){
returntitle;
}
publicvoidsetTitle(Stringtitle){
this.title=title;
}
publicFile[]getUpload(){
returnupload;
}
publicvoidsetUpload(File[]upload){
this.upload=upload;
}
publicString[]getUploadFileName(){
returnuploadFileName;
}
publicvoidsetUploadFileName(String[]uploadFileName){
this.uploadFileName=uploadFileName;
}
publicString[]getUploadContentType(){
returnuploadContentType;
}
publicvoidsetUploadContentType(String[]uploadContentType){
this.uploadContentType=uploadContentType;
}
publicStringgetSavePath(){
returnsavePath;
}
publicvoidsetSavePath(StringsavePath){
this.savePath=savePath;
}
}
package com.trendcom.upload.action; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class UploadFileAction extends BaseAction { private static final int BUFFER_SIZE=16*1024; // 文件标题 private String title; // 用File数组来封装多个上传文件域对象 private File[] upload; // 用String数组来封装多个上传文件名 private String[] uploadFileName; // 用String数组来封装多个上传文件类型 private String[] uploadContentType; // 保存文件的目录路径(通过依赖注入) private String savePath; //以下为所有属性的getter和setter。省略。。。 // 自己封装的一个把源文件对象复制成目标文件对象 private static boolean copy(File src, File dst) { boolean result=false; InputStream in = null; OutputStream out = null; try { in = new BufferedInputStream(new FileInputStream(src), BUFFER_SIZE); out = new BufferedOutputStream(new FileOutputStream(dst), BUFFER_SIZE); byte[] buffer = new byte[BUFFER_SIZE]; int len = 0; while ((len = in.read(buffer)) > 0) { out.write(buffer, 0, len); } result=true; } catch (Exception e) { e.printStackTrace(); result=false; } finally { if (null != in) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } if (null != out) { try { out.close(); } catch (IOException e) { e.printStackTrace(); } } } return result; } @Override public String execute() throws Exception { File[] srcFiles = this.getUpload(); List<String> successFileList=new ArrayList<String>(); // 处理每个要上传的文件 for (int i = 0; i < srcFiles.length; i++) { // 根据服务器的文件保存地址和原文件名创建目录文件全路径 String dstPath = getRealyPath(getSavePath()) + "//" + this.getUploadFileName()[i]; File dstFile = new File(dstPath); if(copy(srcFiles[i], dstFile)){ successFileList.add(getUploadFileName()[i]); } } getRequest().setAttribute("successFileList", successFileList); return SUCCESS; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public File[] getUpload() { return upload; } public void setUpload(File[] upload) { this.upload = upload; } public String[] getUploadFileName() { return uploadFileName; } public void setUploadFileName(String[] uploadFileName) { this.uploadFileName = uploadFileName; } public String[] getUploadContentType() { return uploadContentType; } public void setUploadContentType(String[] uploadContentType) { this.uploadContentType = uploadContentType; } public String getSavePath() { return savePath; } public void setSavePath(String savePath) { this.savePath = savePath; } }
配置文件
Java代码
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEstrutsPUBLIC
"-//ApacheSoftwareFoundation//DTDStrutsConfiguration2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<packagename="com.trendcom.upload.action"extends="struts-default">
<actionname="fileUpload"class="com.trendcom.upload.action.UploadFileAction">
<interceptor-refname="fileUpload">
<!--配置允许上传的文件类型,多个用","分隔-->
<paramname="allowedTypes">
image/bmp,image/png,image/gif,image/jpeg,image/jpg,image/x-png,image/pjpeg
</param>
<!--配置允许上传的文件大小,单位字节-->
<paramname="maximumSize">102400</param>
</interceptor-ref>
<interceptor-refname="defaultStack"/>
<!--动态设置Action中的savePath属性的值-->
<paramname="savePath">/upload</param>
<resultname="input">/index.jsp</result>
<resultname="success">/success.jsp</result>
</action>
</package>
</struts>
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="com.trendcom.upload.action" extends="struts-default"> <action name="fileUpload" class="com.trendcom.upload.action.UploadFileAction"> <interceptor-ref name="fileUpload"> <!-- 配置允许上传的文件类型,多个用","分隔 --> <param name="allowedTypes"> image/bmp,image/png,image/gif,image/jpeg,image/jpg,image/x-png, image/pjpeg </param> <!-- 配置允许上传的文件大小,单位字节 --> <param name="maximumSize">102400</param> </interceptor-ref> <interceptor-ref name="defaultStack" /> <!-- 动态设置Action中的savePath属性的值 --> <param name="savePath">/upload</param> <result name="input">/index.jsp</result> <result name="success">/success.jsp</result> </action> </package> </struts>
所需lib包括(struts2基本包就不在这里列出来)
Java代码
commons-fileupload-1[1].2.jar
commons-io-1.4.jar
commons-fileupload-1[1].2.jar commons-io-1.4.jar
上传类型.当中可能有些是旧的如果想查看struts2中的上传类型可以下载本文的附件.
FileUploadInterceptor
把FileUploadInterceptor.class代替struts2包中类后,就会在控制台中输出所上传的文件是什么类型
Java代码
DescriptionofDataContentTypicalFilenameExtensions
MIMEtype/subtype
TextandText-RelatedTypes
HTMLtextdata(RFC1866)htmlhtmtext/html
Plaintext:documents;programlistingstxtcc++plcchtext/plain
Richtext(obsolete-replacedbytext/enriched)text/richtext
Structureenhancedtext(etx?)text/x-setext
Enrichedtextmarkup(RFC1896)text/enriched
Tab-separatedvalues(tabular)(tsv?)text/tab-separated-values
SGMLdocuments(RFC1874)text/sgml
Speechsynthesisdata(MVPSolutions)talktext/x-speech
DocumentStylesheetTypes
CascadingStylesheetscsstext/css
DSSSL-onlinestylesheetsapplication/dsssl(proposed)
ImageTypes
GIFgifimage/gif
X-Windowsbitmap(b/w)xbmimage/x-xbitmap
X-Windowspixelmap(8-bitcolor)xpmimage/x-xpixmap
PortableNetworkGraphicspngimage/x-png
ImageExchangeFormat(RFC1314)iefimage/ief
JPEGjpegjpgjpeimage/jpeg
TIFFtifftifimage/tiff
RGBrgbimage/rgb
image/x-rgb
GroupIIIFax(RFC1494)g3fimage/g3fax
XWindowdumpformatxwdimage/x-xwindowdump
MacintoshPICTformatpictimage/x-pict
PPM(UNIXPPMpackage)ppmimage/x-portable-pixmap
PGM(UNIXPPMpackage)pgmimage/x-portable-graymap
PBM(UNIXPPMpackage)pbmimage/x-portable-bitmap
PNM(UNIXPPMpackage)pnmimage/x-portable-anymap
MicrosoftWindowsbitmapbmpimage/x-ms-bmp
CMUrasterrasimage/x-cmu-raster
KodakPhoto-CDpcdimage/x-photo-cd
ComputerGraphicsMetafilecgmimage/cgm
NorthAm.PresentationLayerProtocolimage/naplps
CALSType1or2milcalimage/x-cals
FractalImageFormat(IteratedSystems)fifimage/fif
QuickSilveractiveimage(Micrografx)dsfimage/x-mgx-dsf
CMXvectorimage(Corel)cmximage/x-cmx
Wavelet-compressed(Summus)wiimage/wavelet
AutoCadDrawing(SoftSource)dwgimage/vnd.dwg
image/x-dwg
AutoCadDXFfile(SoftSource)dxfimage/vnd.dxf
image/x-dxf
SimpleVectorFormat(SoftSource)svfimage/vnd.svf
alsovector/x-svf
Audio/Voice/MusicRelatedTypes
"basic"audio-8-bitu-lawPCMausndaudio/basic
Macintoshaudioformat(AIpple)aifaiffaifcaudio/x-aiff
Microsoftaudiowavaudio/x-wav
MPEGaudiompaabsmpegaaudio/x-mpeg
MPEG-2audiomp2ampa2audio/x-mpeg-2
compressedspeech(EchoSpeechCorp.)esaudio/echospeech
Toolvoxspeechaudio(Voxware)voxaudio/voxware
RapidTransitcompressedaudio(FastMan)lccapplication/fastman
Realaudio(ProgressiveNetworks)raramapplication/x-pn-realaudio
NIFFmusicnotationdataformatapplication/vnd.music-niff
MIDImusicdatammidx-music/x-midi
Koanmusicdata(SSeyo)skpapplication/vnd.koan
application/x-koan
Speechsynthesisdata(MVPSolutions)talktext/x-speech
VideoTypes
MPEGvideompegmpgmpevideo/mpeg
MPEG-2videompv2mp2vvideo/mpeg-2
MacintoshQuicktimeqtmovvideo/quicktime
Microsoftvideoavivideo/x-msvideo
SGIMovieformatmovievideo/x-sgi-movie
VDOlivestreamingvideo(VDOnet)vdovideo/vdo
Vivostreamingvideo(Vivosoftware)vivvideo/vnd.vivo
video/vivo
SpecialHTTP/WebApplicationTypes
Proxyautoconfiguration(Netscapebrowsers)pacapplication/x-ns-proxy-autoconfig
SeeChapter6application/x-www-form-urlencoded
SeeChapter9application/x-www-local-exec
SeeChapter9(Netscapeextension)multipart/x-mixed-replace
SeeChapter9andAppendixBmultipart/form-data
NetscapeCooltalkchatdata(Netscape)icex-conference/x-cooltalk
Interactivechat(Ichat)application/x-chat
ApplicationTypes
Text-Related
PostScriptaiepspsapplication/postscript
MicrosoftRichTextFormatrtfapplication/rtf
AdobeAcrobatPDFpdfapplication/pdf
application/x-pdf
MakerInterchangeFormat(FrameMaker)mifapplication/vnd.mif
application/x-mif
Troffdocumentttrroffapplication/x-troff
TroffdocumentwithMANmacrosmanapplication/x-troff-man
TroffdocumentwithMEmacrosmeapplication/x-troff-me
TroffdocumentwithMSmacrosmsapplication/x-troff-ms
LaTeXdocumentlatexapplication/x-latex
Tex/LateXdocumenttexapplication/x-tex
GNUTexInfodocumenttexinfotexiapplication/x-texinfo
TeXdviformatdviapplication/x-dvi
MacWritedocument??application/macwriteii
MSworddocument??application/msword
WordPerfect5.1document??application/wordperfect5.1
SGMLapplication(RFC1874)application/sgml
OfficeDocumentArchitectureodaapplication/oda
EnvoyDocumentevyapplication/envoy
WangInfo.TranferFormat(Wang)application/wita
DECDocumentTransferFormat(DEC)application/dec-dx
IBMDocumentContentArchitecture(IBM)application/dca-rft
CommonGroundDigitalPaper(NoHandsSoftware)application/commonground
FrameMakerDocuments(Frame)docfmfrmframeapplication/vnd.framemaker
application/x-framemaker
Remoteprintingatarbitraryprinters(RFC1486)application/remote-printing
Archive/CompressedArchives
Gnutarformatgtarapplication/x-gtar
4.3BSDtarformattarapplication/x-tar
POSIXtarformatustarapplication/x-ustar
OldCPIOformatbcpioapplication/x-bcpio
POSIXCPIOformatcpioapplication/x-cpio
UNIXshshellarchivesharapplication/x-shar
DOS/PC-Pkzippedarchivezipapplication/zip
MacintoshBinhexedarchivehqxapplication/mac-binhex40
MacintoshStuffitArchivesitseaapplication/x-stuffit
FractalImageFormatfifapplication/fractals
Binary,UUencodedbinuuapplication/octet-stream
PCexecutableexeapplication/octet-stream
WAIS"sources"srcwsrcapplication/x-wais-source
NCSAHDFdataformathdfapplication/hdf
DownloadableProgram/Scripts
Javascriptprogramjslsmochatext/javascript
application/x-javascript
VBScriptprogramtext/vbscript
UNIXbourneshellprogramshapplication/x-sh
UNIXc-shellprogramcshapplication/x-csh
Perlprogramplapplication/x-perl
Tcl(ToolControlLanguage)programtclapplication/x-tcl
Atomicmailprogramscripts(obsolete)application/atomicmail
Slatedocuments-executableenclosures(BBN)application/slate
Undefinedbinarydata(oftenexecutableprogs)application/octet-stream
RISCOSExecutableprograms(ANTLimited)application/riscos
Animation/Multimedia
AndrewToolkitinsetapplication/andrew-inset
FutureSplashvectoranimation(FutureWave)splapplication/futuresplash
mBEDmultimediadata(mBED)mbdapplication/mbedlet
MacromediaShockwave(Macromedia)application/x-director
Sizzlerreal-timevideo/animationapplication/x-sprite
PowerMediamultimedia(RadMedia)radapplication/x-rad-powermedia
Presentation
PowerPointpresentation(Microsoft)ppzapplication/mspowerpoint
PointPluspresentationdata(NetScene)cssapplication/x-pointplus
ASAPWordPower(SoftwarePublishingCorp.)aspapplication/x-asap
AstoundWebPlayermultimediadata(GoldDisk)asnapplication/astound
SpecialEmbeddedObject
OLEscripte.g.VisualBasic(Ncompass)axsapplication/x-olescript
OLEObject(Microsoft/NCompass)odsapplication/x-oleobject
OpenScapeOLE/OCXobjects(Business@Web)oppx-form/x-openscape
VisualBasicobjects(Amara)wbaapplication/x-webbasic
Specializeddataentryforms(AlphaSoftware)frmapplication/x-alpha-form
client-serverobjects(WayfarerCommunications)wfxx-script/x-wfxclient
GeneralApplications
Undefinedbinarydata(oftenexecutableprogs)application/octet-stream
CALS(U.S.D.O.Ddataformat-RFC1895)application/cals-1840
Pointcastnewsdata(Pointcast)pcnapplication/x-pcn
Excelspreadsheet(Microsoft)application/vnd.ms-excel
application/x-msexcel
application/ms-excel
PowerPoint(Microsoft)pptapplication/vnd.ms-powerpoint
application/ms-powerpoint
MicrosoftProject(Microsoft)application/vnd.ms-project
Worksdata(Microsoft)application/vnd.ms-works
MAPIdata(Microsoft)application/vnd.ms-tnef
Artgallerydata(Microsoft)application/vnd.artgalry
SourceViewdocument(DatawareElectronics)svdapplication/vnd.svd
Truedoc(Bitstream)application/vnd.truedoc
NetInstall-softwareinstall(20/20Software)insapplication/x-net-install
CarbonCopy-remotecontrol/access(Microcom)ccvapplication/ccv
Spreadsheets(VisualComponents)vtsworkbook/formulaone
Cybercashdigitalmoney(Cybercash)application/cybercash
FormatforsendinggenericMacintoshfilesapplication/applefile
Activemessage--connecttoactivemailapp.application/activemessage
X.400mailmessagebodypart(RFC1494)application/x400-bp
USENETnewsmessageid(RFC1036)application/news-message-id
USENETnewsmessage(RFC1036)application/news-transmission
MultipartTypes(mostlyemail)
Messageswithmultiplepartsmultipart/mixed
Messageswithmultiple,alternativepartsmultipart/alternative
Messagewithmultiple,relatedpartsmultipart/related
Multiplepartsaredigestsmultipart/digest
Forreportingofemailstatus(admin.)multipart/report
Orderofpartsdoesnotmattermultipart/parallel
Macintoshfiledatamultipart/appledouble
Aggregatemessages;descriptorasheadermultipart/header-set
Containerforvoice-mailmultipart/voice-message
HTMLFORMdata(seeCh.9andApp.B)multipart/form-data
Infinitemultiparts-SeeChapter9(Netscape)multipart/x-mixed-replace
MessageTypes(mostlyemail)
MIMEmessagemessage/rfc822
Partialmessagemessage/partial
Messagecontainingexternalreferencesmessage/external-body
MessagecontainingUSENETnewsmessage/news
HTTPmessagemessage/http
2D/3DData/VirtualRealityTypes
VRMLdatafilewrlvrmlx-world/x-vrml
(changingtomodel/vrml)
WIRL-VRMLdata(VREAM)vrwx-world/x-vream
Play3D3dscenedata(Play3D)p3dapplication/x-p3d
ViscapeInteractive3dworlddata(Superscape)svrx-world/x-svr
WebActive3ddata(PlasticThought)wvrx-world/x-wvr
QuickDraw3Dscenedata(Apple)3dmfx-world/x-3dmf
Scientific/Math/CADTypes
Chemicaltypes--tocommunicateinformationaboutchemicalmodelschemical/*(severalsubtypes)
Mathematicanotebookmaapplication/mathematica
Computationalmeshesfornumericalsimulationsmshx-model/x-mesh
(evolvingtomodel/mesh)
Vis5D5-dimensionaldatav5dapplication/vis5d
IGESmodels--CAD/CAM(CGM)dataigsapplication/iges
(evolvingtomodel/iges?)
AutocadWHIPvectordrawingsdwfdrawing/x-dwf
LargelyPlatform-SpecificTypes
SiliconGraphicsSpecificTypes
ShowcasePresentationsshowcaseslidesscshoshowapplication/x-showcase
InsightManualpagesinsinsightapplication/x-insight
IrisAnnotatordataanoapplication/x-annotator
DirectoryViewerdirapplication/x-dirview
SoftwareLicenselicapplication/x-enterlicense
Faxmanagerfilefaxmgrapplication/x-fax-manager
Faxjobdatafilefaxmgrjobapplication/x-fax-manager-job
IconBookdataicnbkapplication/x-iconbook
?wbapplication/x-inpview
Installablesoftwarein'inst'formatinstapplication/x-install
Mailfoldermailapplication/x-mailfolder
?ppppagesapplication/x-ppages
Dataforprinter(vialpr)sgi-lprapplication/x-sgi-lpr
Softwarein'tardist'formattardistapplication/x-tardist
Softwareincompressed'tardist'formatztardistapplication/x-ztardist
WingZspreadsheetwkzapplication/x-wingz
OpenInventor3-Dscenesivgraphics/x-inventor
相关推荐
16. struts.multipart.maxSize:这是multipart请求信息的最大尺寸(文件上传用),Struts2用于限制文件上传的尺寸。 17. struts.multipart.parser:这是一个multipart请求解析器,Struts2用于处理multipart请求。 ...
Struts.xml文件是Apache Struts 2框架的核心配置文件,它用于定义应用程序的行为、Action映射、结果页面、拦截器等关键组件。在深入讲解struts.xml之前,我们先来了解与之相关的struts.properties文件。 struts....
新手必备,看完绝对思路清晰。醍醐灌顶啊! 一. Struts2介绍 1. Struts2简介 2. Struts2和Struts1的常见... 实现文件上传 12. Struts2的拦截器 13. 拒绝表单重复提交 四. OGNL表达式 五. Struts2中常用标签
在第15讲中,我们聚焦于Struts2的文件上传和下载功能,这是web开发中常见的需求。在这里,我们将深入探讨这两个主题,同时也会涉及到一些源码分析和实用工具的使用。 **文件上传** 在Struts2中,文件上传是通过`...
在Struts2中,文件上传和下载是两个重要的功能,常用于处理用户在网页上提交的文件。在第12讲中,我们将深入探讨Struts2如何实现这两个特性。 首先,我们来看文件上传。在Web应用中,用户可能需要上传图片、文档或...
在本篇“Struts2学习笔记十三”中,我们将深入探讨Struts2如何处理文件上传和下载,这是Web开发中常见的需求。 文件上传在Web应用中广泛用于让用户提交图片、文档或其他类型的数据。Struts2提供了一个名为`...
// 保存或处理文件... } return SUCCESS; } } ``` `FileInfo`类需要包含`File`和`String`属性,如: ```java public class FileInfo { private File file; private String fileName; // getters and ...
这个bug是由Struts2上传文件后return SUCCESS后报的错误: java.lang.AbstractMethodError: be.telio.mediastore.ui.upload.GarryMultiPartRequest.cleanUp()V at org.apache.struts2.dispatcher.multipart....
struts.multipart.maxSize 属性指定 Struts 2 文件上传中整个请求内容允许的最大字节数。 11. struts.custom.properties struts.custom.properties 属性指定 Struts 2 应用加载用户自定义的属性文件,该自定义属性...
在本篇“Struts2学习笔记十四”中,我们将深入探讨Struts2框架如何实现文件上传和下载功能,这是web应用中常见的需求,尤其在处理用户提交的表单数据时。我们将不涉及具体代码,而是重点讲解相关概念和技术原理。 ...
专为multipart请求信息使用的org.apache.struts2.dispatcher.multipart.MultiPartRequest解析器接口(文件上传用) struts.multipart.saveDir The directory to use for storing uploaded files 设置存储上传...
// 处理上传的文件... return "success"; } @Override protected void updateProgress(long bytesRead, long contentLength, boolean done) { // 在这里处理进度更新,可以通过contentLength计算当前进度 } ...
在Struts2中,文件上传和下载是常见的功能需求,特别是在处理用户交互和数据交换时。这篇博客文章提供的"struts2文件上传下载源代码"旨在帮助开发者理解和实现这些功能。 文件上传功能允许用户从他们的设备上传文件...
在“struts2文件上传例子.rar”这个项目中,开发者已经使用Struts2.0框架实现了一个简单的文件上传功能。MyEclipse 6.6是一个集成开发环境,支持Java EE项目开发,可以直接导入该项目进行运行和调试。 首先,我们...
在这个“struts2上传文件源代码”中,我们将深入探讨Struts2如何实现文件上传功能,以及涉及到的相关知识点。 首先,文件上传是Web应用中常见的功能,它允许用户从本地计算机选择文件并将其发送到服务器。在Struts2...
需求 1.能够对多个文件进行上传(可以选择上传文件个数,也即上传文件个数不定) 2.能够对上传路径进行配置文件指定(upload.properties),使用...多文件 上传 下载 随意文件 java Struts2 单例 配置 动态读取 李顺利
-- 系统常量定义,定义上传文件字符集编码 --> <constant name="struts.i18n.encoding" value="UTF-8"> <!-- 系统常量定义,定义上传文件临时存放路径 --> <constant name="struts.multipart.saveDir" ...
在本项目中,"struts2多文件的上传"实现了用户一次性上传多个文件的能力。 要理解这个功能,首先我们需要了解Struts2中的Action类和Interceptor(拦截器)。Action类是处理用户请求的核心,而Interceptor则用于处理...
6. **源码分析**: 要深入理解Struts2的文件上传机制,你需要查看Struts2的源码,特别是`org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest`和`org.apache.struts2.components.Form`这两个类。...
在Struts2中,文件上传功能是一个常用特性,尤其在处理用户提交的多个文件时。本文将详细讲解如何使用Struts2进行多个文件的上传,重点是使用List集合进行上传。 首先,要实现Struts2的文件上传,必须引入必要的...