⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 在struts 2中实现文件上传 - max on java - blogjava.htm

📁 struts2标签的详细解释说明教程
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0058)http://www.blogjava.net/max/archive/2007/03/21/105124.html -->
<HTML><HEAD id=Head><TITLE>在Struts 2中实现文件上传 - Max On Java - BlogJava</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<META id=metaKeywords content="在Struts 2中实现文件上传" name=keywords><LINK id=MainCss 
href="在Struts 2中实现文件上传 - Max On Java - BlogJava.files/style.css" type=text/css 
rel=stylesheet><LINK id=RSSLink title=RSS 
href="http://www.blogjava.net/max/rss.aspx" type=application/rss+xml 
rel=alternate>
<META content="MSHTML 6.00.2900.3132" name=GENERATOR></HEAD>
<BODY>
<FORM id=Form1 name=Form1 onsubmit="javascript:return WebForm_OnSubmit();" 
action=105124.html method=post>
<DIV><INPUT id=__EVENTTARGET type=hidden name=__EVENTTARGET> <INPUT 
id=__EVENTARGUMENT type=hidden name=__EVENTARGUMENT> <INPUT 
id="&#13;&#10;__VIEWSTATE" type=hidden name=__VIEWSTATE> </DIV>
<SCRIPT type=text/javascript>
<!--
var theForm = document.forms['Form1'];
if (!theForm) {
    theForm = document.Form1;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
// -->
</SCRIPT>

<SCRIPT src="在Struts 2中实现文件上传 - Max On Java - BlogJava.files/WebResource.axd" 
type=text/javascript></SCRIPT>

<SCRIPT language=JavaScript>
									function ctlent(evt,id)
											{
												if(evt.ctrlKey && evt.keyCode == 13)
												{	
													try
													{
														TempSave(id);
													}
													catch(ex)
													{
													}
													finally
													{
													    __doPostBack('AjaxHolder$PostComment$btnSubmit','')
													}
												}
		
												}</SCRIPT>

<SCRIPT language=JavaScript>function SetReplyAuhor(author){document.getElementById('AjaxHolder_PostComment_tbComment').value+="@"+author+"\n";document.getElementById('AjaxHolder_PostComment_tbComment').focus();return false}</SCRIPT>

<SCRIPT src="在Struts 2中实现文件上传 - Max On Java - BlogJava.files/ScriptResource.axd" 
type=text/javascript></SCRIPT>

<SCRIPT 
src="D:\C_TOOLS\tools\勉強の工具\sql2000 sp4\struts-2.0.9-all\在Struts 2中实现文件上传 - Max On Java - BlogJava.files\ScriptResource(1).axd" 
type=text/javascript></SCRIPT>

<SCRIPT 
src="D:\C_TOOLS\tools\勉強の工具\sql2000 sp4\struts-2.0.9-all\在Struts 2中实现文件上传 - Max On Java - BlogJava.files\ScriptResource(2).axd" 
type=text/javascript></SCRIPT>

<SCRIPT type=text/javascript>
<!--
function WebForm_OnSubmit() {
if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) return false;
return true;
}
// -->
</SCRIPT>
<!--done-->
<DIV id=header><!--done-->
<DIV class=header>
<DIV class=headerText><A class=headermaintitle id=Header1_HeaderTitle 
href="http://www.blogjava.net/max/">Max On Java</A><BR>The value of hands-on 
experience as compared to book learning is smaller in software development than 
in many other fields. </DIV></DIV></DIV>
<DIV id=mytopmenu>
<DIV id=mylinks><!--done--><A class=menu id=MyLinks1_HomeLink 
href="http://www.blogjava.net/">BlogJava</A>&nbsp;&nbsp; <A class=menu 
id=MyLinks1_MyHomeLink href="http://www.blogjava.net/max/">首页</A>&nbsp;&nbsp; <A 
class=menu id=MyLinks1_NewPostLink 
href="http://www.blogjava.net/max/admin/EditPosts.aspx?opt=1">新随笔</A> <A 
class=menu id=MyLinks1_ContactLink 
href="http://www.blogjava.net/max/contact.aspx?id=1">联系</A>&nbsp;&nbsp; <A 
class=menu id=MyLinks1_Syndication 
href="http://www.blogjava.net/max/rss">聚合</A><A id=MyLinks1_XMLLink 
href="http://www.blogjava.net/max/rss"><IMG 
style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" 
src="在Struts 2中实现文件上传 - Max On Java - BlogJava.files/xml.gif"></A>&nbsp;&nbsp; 
<A class=menu id=MyLinks1_Admin 
href="http://www.blogjava.net/max/admin/EditPosts.aspx">管理</A> </DIV>
<DIV id=mystats><!--done-->随笔-18&nbsp; 评论-753&nbsp; 文章-0&nbsp; trackbacks-0 
</DIV></DIV>
<DIV id=centercontent><!--done-->
<DIV class=post>
<DIV class=postTitle><A class=postTitle2 id=viewpost1_TitleUrl 
href="http://www.blogjava.net/max/archive/2007/03/21/105124.html">在Struts 
2中实现文件上传</A> </DIV>
<P>前一阵子有些朋友在电子邮件中问关于Struts 2实现文件上传的问题, 所以今天我们就来讨论一下这个问题。</P>
<H2>实现原理</H2>
<P>Struts 2是通过Commons FileUpload文件上传。Commons 
FileUpload通过将HTTP的数据保存到临时文件夹,然后Struts使用fileUpload拦截器将文件绑定到Action的实例中。从而我们就能够以本地文件方式的操作浏览器上传的文件。</P>
<H2>具体实现</H2>
<P>前段时间Apache发布了Struts 2.0.6 GA,所以本文的实现是以该版本的Struts作为框架的。以下是例子所依赖类包的列表:</P>
<P><IMG alt=依赖类包的列表 
src="在Struts 2中实现文件上传 - Max On Java - BlogJava.files/r_img1.gif">&nbsp;<BR><SPAN 
style="FONT-SIZE: smaller; FONT-STYLE: italic">清单1 依赖类包的列表</SPAN></P>
<P>首先,创建文件上传页面FileUpload.jsp,内容如下:</P>
<DIV 
style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">&lt;%</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">@ page language</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">java</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">contentType</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">text/html; 
charset=utf-8</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">pageEncoding</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">utf-8</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"></SPAN><SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">%&gt;</SPAN> <SPAN 
style="COLOR: #000000"><BR></SPAN><SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">&lt;%</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">@ taglib prefix</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">s</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">uri</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">=</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">/struts-tags</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</SPAN> <SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"></SPAN><SPAN 
style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">%&gt;</SPAN> <SPAN 
style="COLOR: #000000"><BR><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;!</SPAN> 
<SPAN style="COLOR: #ff00ff">DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 
Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</SPAN> <SPAN 
style="COLOR: #0000ff">&gt;</SPAN> <SPAN style="COLOR: #000000"><BR></SPAN><SPAN 
style="COLOR: #0000ff">&lt;</SPAN> <SPAN style="COLOR: #800000">html 
</SPAN><SPAN style="COLOR: #ff0000">xmlns</SPAN> <SPAN 
style="COLOR: #0000ff">="http://www.w3.org/1999/xhtml"</SPAN> <SPAN 
style="COLOR: #0000ff">&gt;</SPAN> <SPAN style="COLOR: #000000"><BR></SPAN><SPAN 
style="COLOR: #0000ff">&lt;</SPAN> <SPAN style="COLOR: #800000">head</SPAN> 
<SPAN style="COLOR: #0000ff">&gt;</SPAN> <SPAN style="COLOR: #000000"><BR>&nbsp; 
&nbsp; </SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN> <SPAN 
style="COLOR: #800000">title</SPAN> <SPAN style="COLOR: #0000ff">&gt;</SPAN> 
<SPAN style="COLOR: #000000">Struts 2 File Upload</SPAN> <SPAN 
style="COLOR: #0000ff">&lt;/</SPAN> <SPAN style="COLOR: #800000">title</SPAN> 
<SPAN style="COLOR: #0000ff">&gt;</SPAN> <SPAN 
style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN> 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -