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

📄 在struts 2中实现ioc - max on java - blogjava.htm

📁 struts2标签的详细解释说明教程
💻 HTM
📖 第 1 页 / 共 5 页
字号:
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.FilterDispatcher<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; </SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN> <SPAN 
style="COLOR: #800000">filter</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-mapping</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">url-pattern</SPAN> <SPAN 
style="COLOR: #0000ff">&gt;</SPAN> <SPAN style="COLOR: #000000">/*</SPAN> <SPAN 
style="COLOR: #0000ff">&lt;/</SPAN> <SPAN 
style="COLOR: #800000">url-pattern</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">filter-mapping</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-mapping</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">struts2</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">url-pattern</SPAN> <SPAN 
style="COLOR: #0000ff">&gt;</SPAN> <SPAN style="COLOR: #000000">/*</SPAN> <SPAN 
style="COLOR: #0000ff">&lt;/</SPAN> <SPAN 
style="COLOR: #800000">url-pattern</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">filter-mapping</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">listener</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">listener-class</SPAN> <SPAN 
style="COLOR: #0000ff">&gt;</SPAN> <SPAN style="COLOR: #000000"><BR>&nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
org.springframework.web.context.ContextLoaderListener<BR>&nbsp; &nbsp; &nbsp; 
&nbsp; </SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN> <SPAN 
style="COLOR: #800000">listener-class</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">listener</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">welcome-file-list</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">welcome-file</SPAN> <SPAN 
style="COLOR: #0000ff">&gt;</SPAN> <SPAN 
style="COLOR: #000000">index.html</SPAN> <SPAN 
style="COLOR: #0000ff">&lt;/</SPAN> <SPAN 
style="COLOR: #800000">welcome-file</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">welcome-file-list</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: #0000ff">&gt;</SPAN> </DIV><SPAN 
style="FONT-SIZE: smaller; FONT-STYLE: italic">清单1 WEB-INF\web.xml</SPAN> 
<P>大家一看便知道,主要是加入Spring的ContextLoaderListener监听器,方便Spring与Web容器交互。</P>
<P>紧接着,修改Struts.properties文件,告知Struts 2运行时使用Spring来创建对象(如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: #000000">struts.objectFactory</SPAN> <SPAN 
style="COLOR: #000000">=</SPAN> <SPAN style="COLOR: #000000">spring</SPAN> 
</DIV><SPAN style="FONT-SIZE: smaller; FONT-STYLE: italic">清单2 
classes\struts.properties</SPAN> 
<P>再下来,遵循Spring的原则——面向接口编程,创建接口ChatService,代码如下:</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"><IMG 
src="在Struts 2中实现IoC - Max On Java - BlogJava.files/None.gif" align=top> <SPAN 
style="COLOR: #0000ff">package</SPAN> <SPAN 
style="COLOR: #000000">tutorial;<BR><IMG 
src="在Struts 2中实现IoC - Max On Java - BlogJava.files/None.gif" align=top><BR><IMG 
src="在Struts 2中实现IoC - Max On Java - BlogJava.files/None.gif" align=top></SPAN> 
<SPAN style="COLOR: #0000ff">import</SPAN> <SPAN 
style="COLOR: #000000">java.util.Set;<BR><IMG 
src="在Struts 2中实现IoC - Max On Java - BlogJava.files/None.gif" align=top><BR><IMG 
id=Codehighlighter1_71_102_Open_Image 
onclick="this.style.display='none'; Codehighlighter1_71_102_Open_Text.style.display='none'; Codehighlighter1_71_102_Closed_Image.style.display='inline'; Codehighlighter1_71_102_Closed_Text.style.display='inline';" 
src="在Struts 2中实现IoC - Max On Java - BlogJava.files/ExpandedBlockStart.gif" 
align=top><IMG id=Codehighlighter1_71_102_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; Codehighlighter1_71_102_Closed_Text.style.display='none'; Codehighlighter1_71_102_Open_Image.style.display='inline'; Codehighlighter1_71_102_Open_Text.style.display='inline';" 
src="在Struts 2中实现IoC - Max On Java - BlogJava.files/ContractedBlock.gif" 
align=top></SPAN> <SPAN style="COLOR: #0000ff">public</SPAN> <SPAN 
style="COLOR: #000000"></SPAN><SPAN style="COLOR: #0000ff">interface</SPAN> 
<SPAN style="COLOR: #000000">ChatService </SPAN><SPAN 
id=Codehighlighter1_71_102_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
src="在Struts 2中实现IoC - Max On Java - BlogJava.files/dot.gif"> </SPAN><SPAN 
id=Codehighlighter1_71_102_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
src="在Struts 2中实现IoC - Max On Java - BlogJava.files/InBlock.gif" align=top> 
&nbsp; &nbsp;Set</SPAN> <SPAN style="COLOR: #000000">&lt;</SPAN> <SPAN 
style="COLOR: #000000">String</SPAN> <SPAN style="COLOR: #000000">&gt;</SPAN> 
<SPAN style="COLOR: #000000">getUserNames();<BR><IMG 
src="在Struts 2中实现IoC - Max On Java - BlogJava.files/ExpandedBlockEnd.gif" 
align=top>}</SPAN> </SPAN></DIV><SPAN 
style="FONT-SIZE: smaller; FONT-STYLE: italic">清单3 
tutorial.ChatService.java</SPAN> 
<P>然后,再创建一个默认实现ChatServiceImpl,代码如下:</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"><IMG 
src="在Struts 2中实现IoC - Max On Java - BlogJava.files/None.gif" align=top> <SPAN 
style="COLOR: #0000ff">package</SPAN> <SPAN 
style="COLOR: #000000">tutorial;<BR><IMG 
src="在Struts 2中实现IoC - Max On Java - BlogJava.files/None.gif" align=top><BR><IMG 
src="在Struts 2中实现IoC - Max On Java - BlogJava.files/None.gif" align=top></SPAN> 
<SPAN style="COLOR: #0000ff">import</SPAN> <SPAN 
style="COLOR: #000000">java.util.HashSet;<BR><IMG 
src="在Struts 2中实现IoC - Max On Java - BlogJava.files/None.gif" align=top></SPAN> 
<SPAN style="COLOR: #0000ff">import</SPAN> <SPAN 
style="COLOR: #000000">java.util.Set;<BR><IMG 
src="在Struts 2中实现IoC - Max On Java - BlogJava.files/None.gif" align=top><BR><IMG 
id=Codehighlighter1_120_287_Open_Image 
onclick="this.style.display='none'; Codehighlighter1_120_287_Open_Text.style.display='none'; Codehighlighter1_120_287_Closed_Image.style.display='inline'; Codehighlighter1_120_287_Closed_Text.style.display='inline';" 
src="在Struts 2中实现IoC - Max On Java - BlogJava.files/ExpandedBlockStart.gif" 
align=top><IMG id=Codehighlighter1_120_287_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; Codehighlighter1_120_287_Closed_Text.style.display='none'; Codehighlighter1_120_287_Open_Image.style.display='inline'; Codehighlighter1_120_287_Open_Text.style.display='inline';" 
src="在Struts 2中实现IoC - Max On Java - BlogJava.files/ContractedBlock.gif" 
align=top></SPAN> <SPAN style="COLOR: #0000ff">public</SPAN> <SPAN 
style="COLOR: #000000"></SPAN><SPAN style="COLOR: #0000ff">class</SPAN> <SPAN 
style="COLOR: #000000">ChatServiceImpl </SPAN><SPAN 
style="COLOR: #0000ff">implements</SPAN> <SPAN 
style="COLOR: #000000">ChatService </SPAN><SPAN 
id=Codehighlighter1_120_287_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
src="在Struts 2中实现IoC - Max On Java - BlogJava.files/dot.gif"> </SPAN><SPAN 
id=Codehighlighter1_120_287_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
src="在Struts 2中实现IoC - Max On Java - BlogJava.files/InBlock.gif" 
align=top><BR><IMG id=Codehighlighter1_158_284_Open_Image 
onclick="this.style.display='none'; Codehighlighter1_158_284_Open_Text.style.display='none'; Codehighlighter1_158_284_Closed_Image.style.display='inline'; Codehighlighter1_158_284_Closed_Text.style.display='inline';" 
src="在Struts 2中实现IoC - Max On Java - BlogJava.files/ExpandedSubBlockStart.gif" 
align=top><IMG id=Codehighlighter1_158_284_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; Codehighlighter1_158_284_Closed_Text.style.display='none'; Codehighlighter1_158_284_Open_Image.style.display='inline'; Codehighlighter1_158_284_Open_Text.style.display='inline';" 
src="在Struts 2中实现IoC - Max On Java - BlogJava.files/ContractedSubBlock.gif" 
align=top> &nbsp; &nbsp;</SPAN> <SPAN style="COLOR: #0000ff">public</SPAN> <SPAN 
style="COLOR: #000000">Set</SPAN> <SPAN style="COLOR: #000000">&lt;</SPAN> <SPAN 
style="COLOR: #000000">String</SPAN> <SPAN style="COLOR: #000000">&gt;</SPAN> 
<SPAN style="COLOR: #000000">getUserNames() </SPAN><SPAN 
id=Codehighlighter1_158_284_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
src="在Struts 2中实现IoC - Max On Java - BlogJava.files/dot.gif"> </SPAN><SPAN 
id=Codehighlighter1_158_284_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
src="在Struts 2中实现IoC - Max On Java - BlogJava.files/InBlock.gif" align=top> 
&nbsp; &nbsp; &nbsp; &nbsp;Set</SPAN> <SPAN style="COLOR: #000000">&lt;</SPAN> 
<SPAN style="COLOR: #000000">String</SPAN> <SPAN 
style="COLOR: #000000">&gt;</SPAN> <SPAN style="COLOR: #000000">users 
</SPAN><SPAN style="COLOR: #000000">=</SPAN> <SPAN 
style="COLOR: #000000"></SPAN><SPAN style="COLOR: #0000ff">new</SPAN> <SPAN 
style="COLOR: #000000">HashSet</SPAN> <SPAN style="COLOR: #000000">&lt;</SPAN> 
<SPAN style="COLOR: #000000">String</SPAN> <SPAN 
style="COLOR: #000000">&gt;</SPAN> <SPAN style="COLOR: #000000">();<BR><IMG 
src="在Struts 2中实现IoC - Max On Java - BlogJava.files/InBlock.gif" align=top> 
&nbsp; &nbsp; &nbsp; &nbsp;users.add(</SPAN> <SPAN 
style="COLOR: #000000">"</SPAN> <SPAN style="COLOR: #000000">Max</SPAN> <SPAN 
style="COLOR: #000000">"</SPAN> <SPAN style="COLOR: #000000">);<BR><IMG 
src="在Struts 2中实现IoC - Max On Java - BlogJava.files/InBlock.gif" align=top> 
&nbsp; &nbsp; &nbsp; &nbsp;users.add(</SPAN> <SPAN 
style="COLOR: #000000">"</SPAN> <SPAN style="COLOR: #000000">Scott</SPAN> <SPAN 
style="COLOR: #000000">"</SPAN> <SPAN style="COLOR: #000000">);<BR><IMG 

⌨️ 快捷键说明

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