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

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

📁 struts2标签的详细解释说明教程
💻 HTM
📖 第 1 页 / 共 5 页
字号:
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> 
<SPAN style="COLOR: #800000">head</SPAN> <SPAN 
style="COLOR: #0000ff">&gt;</SPAN> <SPAN style="COLOR: #000000"><BR></SPAN><SPAN 
style="COLOR: #0000ff">&lt;</SPAN> <SPAN style="COLOR: #800000">body</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">div </SPAN><SPAN style="COLOR: #ff0000">style</SPAN> 
<SPAN style="COLOR: #0000ff">="padding: 3px; border: solid 1px #cccccc; 
text-align: center"</SPAN> <SPAN style="COLOR: #0000ff">&gt;</SPAN> <SPAN 
style="COLOR: #000000"><BR>&nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN 
style="COLOR: #0000ff">&lt;</SPAN> <SPAN style="COLOR: #800000">img </SPAN><SPAN 
style="COLOR: #ff0000">src</SPAN> <SPAN 
style="COLOR: #0000ff">='UploadImages/&lt;s:property </SPAN><SPAN 
style="COLOR: #ff0000">value</SPAN> <SPAN 
style="COLOR: #0000ff">="imageFileName"</SPAN> <SPAN 
style="COLOR: #ff0000"></SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN> <SPAN 
style="COLOR: #000000">' /&gt;<BR>&nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN 
style="COLOR: #0000ff">&lt;</SPAN> <SPAN style="COLOR: #800000">br </SPAN><SPAN 
style="COLOR: #0000ff">/&gt;</SPAN> <SPAN style="COLOR: #000000"><BR>&nbsp; 
&nbsp; &nbsp; &nbsp; </SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN> <SPAN 
style="COLOR: #800000">s:property </SPAN><SPAN 
style="COLOR: #ff0000">value</SPAN> <SPAN 
style="COLOR: #0000ff">="caption"</SPAN> <SPAN 
style="COLOR: #ff0000"></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">div</SPAN> 
<SPAN style="COLOR: #0000ff">&gt;</SPAN> <SPAN 
style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN> 
<SPAN style="COLOR: #800000">body</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: #0000ff">&gt;</SPAN> </DIV><SPAN 
style="FONT-SIZE: smaller; FONT-STYLE: italic">清单4 ShowUpload.jsp</SPAN> 
<P>ShowUpload.jsp获得imageFileName,将其UploadImages组成URL,从而将上传的图像显示出来。</P>
<P>然后是Action的配置文件:</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: #0000ff">&lt;?</SPAN> <SPAN style="COLOR: #ff00ff">xml 
version="1.0" encoding="UTF-8"</SPAN> <SPAN style="COLOR: #0000ff">?&gt;</SPAN> 
<SPAN style="COLOR: #000000"><BR><BR></SPAN><SPAN 
style="COLOR: #0000ff">&lt;!</SPAN> <SPAN style="COLOR: #ff00ff">DOCTYPE struts 
PUBLIC<BR>&nbsp; &nbsp; "-//Apache Software Foundation//DTD Struts Configuration 
2.0//EN"<BR>&nbsp; &nbsp; "http://struts.apache.org/dtds/struts-2.0.dtd"</SPAN> 
<SPAN style="COLOR: #0000ff">&gt;</SPAN> <SPAN 
style="COLOR: #000000"><BR><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN> 
<SPAN style="COLOR: #800000">struts</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">package </SPAN><SPAN style="COLOR: #ff0000">name</SPAN> 
<SPAN style="COLOR: #0000ff">="fileUploadDemo"</SPAN> <SPAN 
style="COLOR: #ff0000">extends</SPAN> <SPAN 
style="COLOR: #0000ff">="struts-default"</SPAN> <SPAN 
style="COLOR: #0000ff">&gt;</SPAN> <SPAN style="COLOR: #000000"><BR>&nbsp; 
&nbsp; &nbsp; &nbsp; </SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN> <SPAN 
style="COLOR: #800000">action </SPAN><SPAN style="COLOR: #ff0000">name</SPAN> 
<SPAN style="COLOR: #0000ff">="fileUpload"</SPAN> <SPAN 
style="COLOR: #ff0000">class</SPAN> <SPAN 
style="COLOR: #0000ff">="tutorial.FileUploadAction"</SPAN> <SPAN 
style="COLOR: #0000ff">&gt;</SPAN> <SPAN style="COLOR: #000000"><BR>&nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN 
style="COLOR: #0000ff">&lt;</SPAN> <SPAN style="COLOR: #800000">interceptor-ref 
</SPAN><SPAN style="COLOR: #ff0000">name</SPAN> <SPAN 
style="COLOR: #0000ff">="fileUploadStack"</SPAN> <SPAN 
style="COLOR: #ff0000"></SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN> <SPAN 
style="COLOR: #000000"><BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN> <SPAN 
style="COLOR: #800000">result </SPAN><SPAN style="COLOR: #ff0000">name</SPAN> 
<SPAN style="COLOR: #0000ff">="success"</SPAN> <SPAN 
style="COLOR: #0000ff">&gt;</SPAN> <SPAN 
style="COLOR: #000000">/ShowUpload.jsp</SPAN> <SPAN 
style="COLOR: #0000ff">&lt;/</SPAN> <SPAN style="COLOR: #800000">result</SPAN> 
<SPAN style="COLOR: #0000ff">&gt;</SPAN> <SPAN style="COLOR: #000000"><BR>&nbsp; 
&nbsp; &nbsp; &nbsp; </SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN> <SPAN 
style="COLOR: #800000">action</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">package</SPAN> 
<SPAN style="COLOR: #0000ff">&gt;</SPAN> <SPAN 
style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN> 
<SPAN style="COLOR: #800000">struts</SPAN> <SPAN 
style="COLOR: #0000ff">&gt;</SPAN> </DIV><SPAN 
style="FONT-SIZE: smaller; FONT-STYLE: italic">清单5 struts.xml</SPAN> 
<P>fileUpload Action显式地应用fileUploadStack的拦截器。</P>
<P>最后是web.xml配置文件:</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: #0000ff">&lt;?</SPAN> <SPAN style="COLOR: #ff00ff">xml 
version="1.0" encoding="UTF-8"</SPAN> <SPAN style="COLOR: #0000ff">?&gt;</SPAN> 
<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN> 
<SPAN style="COLOR: #800000">web-app </SPAN><SPAN 
style="COLOR: #ff0000">id</SPAN> <SPAN style="COLOR: #0000ff">="WebApp_9"</SPAN> 
<SPAN style="COLOR: #ff0000">version</SPAN> <SPAN 
style="COLOR: #0000ff">="2.4"</SPAN> <SPAN style="COLOR: #ff0000"><BR>&nbsp; 
&nbsp; xmlns</SPAN> <SPAN 
style="COLOR: #0000ff">="http://java.sun.com/xml/ns/j2ee"</SPAN> <SPAN 
style="COLOR: #ff0000"><BR>&nbsp; &nbsp; xmlns:xsi</SPAN> <SPAN 
style="COLOR: #0000ff">="http://www.w3.org/2001/XMLSchema-instance"</SPAN> <SPAN 
style="COLOR: #ff0000"><BR>&nbsp; &nbsp; xsi:schemaLocation</SPAN> <SPAN 
style="COLOR: #0000ff">="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"</SPAN> <SPAN 
style="COLOR: #0000ff">&gt;</SPAN> <SPAN style="COLOR: #000000"><BR><BR>&nbsp; 
&nbsp; </SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN> <SPAN 
style="COLOR: #800000">display-name</SPAN> <SPAN 
style="COLOR: #0000ff">&gt;</SPAN> <SPAN style="COLOR: #000000">Struts 2 
Fileupload</SPAN> <SPAN style="COLOR: #0000ff">&lt;/</SPAN> <SPAN 
style="COLOR: #800000">display-name</SPAN> <SPAN 
style="COLOR: #0000ff">&gt;</SPAN> <SPAN style="COLOR: #000000"><BR><BR>&nbsp; 
&nbsp; </SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN> <SPAN 
style="COLOR: #800000">filter</SPAN> <SPAN style="COLOR: #0000ff">&gt;</SPAN> 
<SPAN style="COLOR: #000000"><BR>&nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN 
style="COLOR: #0000ff">&lt;</SPAN> <SPAN 
style="COLOR: #800000">filter-name</SPAN> <SPAN 
style="COLOR: #0000ff">&gt;</SPAN> <SPAN 
style="COLOR: #000000">struts-cleanup</SPAN> <SPAN 
style="COLOR: #0000ff">&lt;/</SPAN> <SPAN 
style="COLOR: #800000">filter-name</SPAN> <SPAN 
style="COLOR: #0000ff">&gt;</SPAN> <SPAN style="COLOR: #000000"><BR>&nbsp; 
&nbsp; &nbsp; &nbsp; </SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN> <SPAN 
style="COLOR: #800000">filter-class</SPAN> <SPAN 
style="COLOR: #0000ff">&gt;</SPAN> <SPAN style="COLOR: #000000"><BR>&nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
org.apache.struts2.dispatcher.ActionContextCleanUp<BR>&nbsp; &nbsp; &nbsp; 
&nbsp; </SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN> <SPAN 
style="COLOR: #800000">filter-class</SPAN> <SPAN 
style="COLOR: #0000ff">&gt;</SPAN> <SPAN style="COLOR: #000000"><BR>&nbsp; 
&nbsp; <

⌨️ 快捷键说明

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