📄 csdn_文档中心_struts快速学习指南6(内部培训教材)-大部分素材来自于《programming jakarta struts》一书.htm
字号:
style="FONT-SIZE: 12pt; mso-ansi-language: DA"><FONT
color=#354278>Action</FONT></SPAN></TT><FONT face=宋体
size=2>类只会被实例化一次,供所有线程共享。</FONT><TT><SPAN lang=DA
style="FONT-SIZE: 12pt; mso-ansi-language: DA"><FONT
color=#354278>RequestProcessor</FONT></SPAN></TT><FONT face=宋体
size=2>利用一个</FONT><TT><SPAN lang=DA
style="FONT-SIZE: 12pt; mso-ansi-language: DA"><FONT
color=#354278>HashMap</FONT></SPAN></TT><FONT face=宋体
size=2>用来保存</FONT><TT><SPAN lang=DA
style="FONT-SIZE: 12pt; mso-ansi-language: DA"><FONT
color=#354278>Action</FONT></SPAN></TT><FONT face=宋体
size=2>实例。</FONT></P>
<TABLE class=MsoTableGrid
style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext"
cellSpacing=0 cellPadding=0 border=1>
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-lastrow: yes">
<TD
style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 478.8pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt"
vAlign=top width=638>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
style="COLOR: red"><FONT size=2><FONT face=宋体>思考题?<SPAN
lang=EN-US><o:p></o:p></SPAN></FONT></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT face=宋体
size=2>所有线程共享一个</FONT><TT><SPAN lang=DA
style="FONT-SIZE: 12pt; mso-ansi-language: DA"><FONT
color=#354278>Action</FONT></SPAN></TT><FONT face=宋体
size=2>类实例意味着什么?我们在编程中需要注意些什么呢?</FONT></P></TD></TR></TBODY></TABLE>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 18pt; mso-char-indent-count: 1.8"><SPAN
lang=EN-US><o:p><FONT face=宋体 size=2> </FONT></o:p></SPAN></P>
<H4 style="MARGIN: 6pt 0cm 3pt; TEXT-INDENT: 0cm"><A
name=_Toc70351639></A><A name=_Toc69320859><SPAN
style="mso-bookmark: _Toc70351639"><SPAN lang=EN-US
style="mso-bidi-font-family: 宋体"><SPAN
style="mso-list: Ignore"><FONT face=宋体 size=2>1.1.1.2</FONT><SPAN
style="FONT: 7pt 'Times New Roman'">
</SPAN></SPAN></SPAN><SPAN lang=EN-US><FONT face=宋体
size=2>ActionForward类</FONT></SPAN></SPAN></A></H4>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 18pt; mso-char-indent-count: 1.8"><SPAN
style="mso-ansi-language: DA"><FONT face=宋体
size=2>从前面的介绍我们已经了解到,</FONT></SPAN><TT><SPAN lang=DA
style="FONT-SIZE: 12pt; mso-ansi-language: DA"><FONT
color=#354278>Action</FONT></SPAN></TT><SPAN
style="mso-ansi-language: DA"><FONT face=宋体
size=2>的</FONT></SPAN><TT><SPAN lang=DA
style="FONT-SIZE: 12pt; mso-ansi-language: DA"><FONT
color=#354278>execute( )</FONT></SPAN></TT><SPAN
style="mso-ansi-language: DA"><FONT face=宋体
size=2>方法返回一个</FONT></SPAN><TT><SPAN lang=DA
style="FONT-SIZE: 12pt; mso-ansi-language: DA"><FONT
color=#354278>ActionForward</FONT></SPAN></TT><SPAN
style="mso-ansi-language: DA"><FONT face=宋体
size=2>对象。</FONT></SPAN><TT><SPAN lang=DA
style="FONT-SIZE: 12pt; mso-ansi-language: DA"><FONT
color=#354278>ActionForward</FONT></SPAN></TT><SPAN
style="mso-ansi-language: DA"><FONT size=2><FONT face=宋体>对象是<SPAN
lang=DA>JSP</SPAN>页面、<SPAN lang=DA>Java servlet</SPAN>等<SPAN
lang=DA>web</SPAN>资源的抽象表现。<SPAN
lang=DA><o:p></o:p></SPAN></FONT></FONT></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21.6pt; LINE-HEIGHT: normal; mso-char-indent-count: 1.8; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><TT><SPAN
lang=DA style="FONT-SIZE: 12pt; mso-ansi-language: DA"><FONT
color=#354278>ActionForward</FONT></SPAN></TT><FONT size=2><SPAN
style="LAYOUT-GRID-MODE: both; COLOR: black; mso-ascii-font-family: 'Times New Roman'; mso-ansi-language: DA"><FONT
face=宋体>的用途是为了减少应用和物理资源</FONT></SPAN><SPAN lang=DA
style="LAYOUT-GRID-MODE: both; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-ansi-language: DA">(JSP</SPAN><SPAN
style="LAYOUT-GRID-MODE: both; COLOR: black; mso-ascii-font-family: 'Times New Roman'; mso-ansi-language: DA"><FONT
face=宋体>页面,</FONT></SPAN><SPAN lang=DA
style="LAYOUT-GRID-MODE: both; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-ansi-language: DA">Java
servlet)</SPAN><SPAN
style="LAYOUT-GRID-MODE: both; COLOR: black; mso-ascii-font-family: 'Times New Roman'; mso-ansi-language: DA"><FONT
face=宋体>的耦合,物理资源只需要在配置文件中指定</FONT></SPAN><SPAN lang=DA
style="LAYOUT-GRID-MODE: both; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-ansi-language: DA">(</SPAN><SPAN
style="LAYOUT-GRID-MODE: both; COLOR: black; mso-ascii-font-family: 'Times New Roman'; mso-ansi-language: DA"><FONT
face=宋体>利用</FONT></SPAN><SPAN lang=DA
style="LAYOUT-GRID-MODE: both; COLOR: #354278; FONT-FAMILY: 'Courier New'; mso-ansi-language: DA">name</SPAN><SPAN
lang=DA
style="LAYOUT-GRID-MODE: both; FONT-FAMILY: 'Times New Roman'; mso-ansi-language: DA">,</SPAN><SPAN
lang=DA
style="LAYOUT-GRID-MODE: both; COLOR: #354278; FONT-FAMILY: 'Courier New'; mso-ansi-language: DA">path</SPAN><SPAN
style="LAYOUT-GRID-MODE: both; COLOR: black; mso-ascii-font-family: 'Times New Roman'; mso-ansi-language: DA"><FONT
face=宋体>属性和</FONT></SPAN><SPAN lang=DA
style="LAYOUT-GRID-MODE: both; COLOR: #354278; FONT-FAMILY: 'Courier New'; mso-ansi-language: DA">forward</SPAN><SPAN
style="LAYOUT-GRID-MODE: both; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-ansi-language: DA"><FONT
face=宋体>元素的</FONT></SPAN><SPAN lang=DA
style="LAYOUT-GRID-MODE: both; COLOR: #354278; FONT-FAMILY: 'Courier New'; mso-ansi-language: DA">redirect</SPAN><SPAN
style="LAYOUT-GRID-MODE: both; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-ansi-language: DA"><FONT
face=宋体>属性</FONT></SPAN><SPAN lang=DA
style="LAYOUT-GRID-MODE: both; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-ansi-language: DA">)</SPAN><SPAN
style="LAYOUT-GRID-MODE: both; COLOR: black; mso-ascii-font-family: 'Times New Roman'; mso-ansi-language: DA"><FONT
face=宋体>,而不是在代码中指定。</FONT></SPAN><SPAN lang=DA
style="LAYOUT-GRID-MODE: both; COLOR: #354278; FONT-FAMILY: 'Courier New'; mso-ansi-language: DA">RequestDispatcher</SPAN><SPAN
style="LAYOUT-GRID-MODE: both; COLOR: black; mso-ascii-font-family: 'Times New Roman'; mso-ansi-language: DA"><FONT
face=宋体>利用</FONT></SPAN><SPAN lang=DA
style="LAYOUT-GRID-MODE: both; COLOR: #354278; FONT-FAMILY: 'Courier New'; mso-ansi-language: DA">ActionForward</SPAN><SPAN
style="LAYOUT-GRID-MODE: both; COLOR: black; mso-ascii-font-family: 'Times New Roman'; mso-ansi-language: DA"><FONT
face=宋体>来执行重定向操作。</FONT></SPAN><SPAN lang=DA
style="LAYOUT-GRID-MODE: both; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-ansi-language: DA">
<o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal; mso-char-indent-count: 1.8; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><FONT
size=2><SPAN
style="LAYOUT-GRID-MODE: both; COLOR: black; mso-ascii-font-family: 'Times New Roman'; mso-ansi-language: DA"><FONT
face=宋体>要在</FONT></SPAN><SPAN lang=DA
style="LAYOUT-GRID-MODE: both; COLOR: #354278; FONT-FAMILY: 'Courier New'; mso-ansi-language: DA">Action</SPAN><SPAN
style="LAYOUT-GRID-MODE: both; COLOR: black; mso-ascii-font-family: 'Times New Roman'; mso-ansi-language: DA"><FONT
face=宋体>中返回一个</FONT></SPAN><SPAN lang=DA
style="LAYOUT-GRID-MODE: both; COLOR: #354278; FONT-FAMILY: 'Courier New'; mso-ansi-language: DA">ActionForward</SPAN><SPAN
style="LAYOUT-GRID-MODE: both; COLOR: black; mso-ascii-font-family: 'Times New Roman'; mso-ansi-language: DA"><FONT
face=宋体>对象,你可以动态地创建一个</FONT></SPAN><SPAN lang=DA
style="LAYOUT-GRID-MODE: both; COLOR: #354278; FONT-FAMILY: 'Courier New'; mso-ansi-language: DA">ActionForward</SPAN><SPAN
lang=DA
style="LAYOUT-GRID-MODE: both; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-ansi-language: DA">
</SPAN><SPAN
style="LAYOUT-GRID-MODE: both; COLOR: black; mso-ascii-font-family: 'Times New Roman'; mso-ansi-language: DA"><FONT
face=宋体>对象,不过更为通用的解决方案是,通过在</FONT></SPAN><SPAN lang=DA
style="LAYOUT-GRID-MODE: both; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-ansi-language: DA">Struts</SPAN><SPAN
style="LAYOUT-GRID-MODE: both; COLOR: black; mso-ascii-font-family: 'Times New Roman'; mso-ansi-language: DA"><FONT
face=宋体>配置文件中进行</FONT></SPAN><SPAN lang=DA
style="LAYOUT-GRID-MODE: both; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-ansi-language: DA">action</SPAN><SPAN
style="LAYOUT-GRID-MODE: both; COLOR: black; mso-ascii-font-family: 'Times New Roman'; mso-ansi-language: DA"><FONT
face=宋体>映射,然后通过关键字去查找一个</FONT></SPAN><SPAN lang=DA
style="LAYOUT-GRID-MODE: both; COLOR: #354278; FONT-FAMILY: 'Courier New'; mso-ansi-language: DA">ActionForward</SPAN><SPAN
lang=DA
style="LAYOUT-GRID-MODE: both; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-ansi-language: DA">
</SPAN><SPAN
style="LAYOUT-GRID-MODE: both; mso-ascii-font-family: 'Times New Roman'; mso-ansi-language: DA"><FONT
face=宋体>。下面是代码示例:</FONT></SPAN><SPAN lang=DA
style="LAYOUT-GRID-MODE: both; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-ansi-language: DA">
<o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal; mso-char-indent-count: 1.8; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"><SPAN
lang=DA
style="LAYOUT-GRID-MODE: both; COLOR: #354278; FONT-FAMILY: 'Courier New'; mso-ansi-language: DA"><FONT
size=2> return mapping.findForward( "Success"
);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 18pt; LINE-HEIGHT: normal; mso-char-indent-count: 1.8; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><FONT
size=2><SPAN
style="LAYOUT-GRID-MODE: both; COLOR: black; mso-ascii-font-family: 'Times New Roman'; mso-ansi-language: DA"><FONT
face=宋体>上面的代码中,</FONT></SPAN><SPAN lang=DA
style="LAYOUT-GRID-MODE: both; COLOR: #354278; FONT-FAMILY: 'Courier New'; mso-ansi-language: DA">"Success"</SPAN><SPAN
style="LAYOUT-GRID-MODE: both; COLOR: black; mso-ascii-font-family: 'Times New Roman'; mso-ansi-language: DA"><FONT
face=宋体>作为参数被传递到</FONT></SPAN><SPAN lang=DA
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -