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

📄 struts 2的基石——拦截器(interceptor) - max on java - blogjava.htm

📁 struts2标签的详细解释说明教程
💻 HTM
📖 第 1 页 / 共 5 页
字号:
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的基石——拦截器(Interceptor) - 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的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/None.gif" 
align=top><BR><IMG id=Codehighlighter1_46_76_Open_Image 
onclick="this.style.display='none'; Codehighlighter1_46_76_Open_Text.style.display='none'; Codehighlighter1_46_76_Closed_Image.style.display='inline'; Codehighlighter1_46_76_Closed_Text.style.display='inline';" 
src="Struts 2的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/ExpandedBlockStart.gif" 
align=top><IMG id=Codehighlighter1_46_76_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; Codehighlighter1_46_76_Closed_Text.style.display='none'; Codehighlighter1_46_76_Open_Image.style.display='inline'; Codehighlighter1_46_76_Open_Text.style.display='inline';" 
src="Struts 2的基石——拦截器(Interceptor) - 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">RoleAware </SPAN><SPAN 
id=Codehighlighter1_46_76_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的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/dot.gif"> 
</SPAN><SPAN id=Codehighlighter1_46_76_Open_Text><SPAN 
style="COLOR: #000000">{<BR><IMG 
src="Struts 2的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/InBlock.gif" 
align=top> &nbsp; &nbsp;</SPAN> <SPAN style="COLOR: #0000ff">void</SPAN> <SPAN 
style="COLOR: #000000">setRole(String role);<BR><IMG 
src="Struts 2的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/ExpandedBlockEnd.gif" 
align=top>}</SPAN> </SPAN></DIV>
<P>接着,创建Action类tutorial.AuthorizatedAccess模拟访问受限资源,它作用就是通过实现RoleAware获取角色,并将其显示到ShowUser.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"><IMG 
src="Struts 2的基石——拦截器(Interceptor) - 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的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/None.gif" 
align=top><BR><IMG 
src="Struts 2的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/None.gif" 
align=top></SPAN> <SPAN style="COLOR: #0000ff">import</SPAN> <SPAN 
style="COLOR: #000000">com.opensymphony.xwork2.ActionSupport;<BR><IMG 
src="Struts 2的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/None.gif" 
align=top><BR><IMG id=Codehighlighter1_141_333_Open_Image 
onclick="this.style.display='none'; Codehighlighter1_141_333_Open_Text.style.display='none'; Codehighlighter1_141_333_Closed_Image.style.display='inline'; Codehighlighter1_141_333_Closed_Text.style.display='inline';" 
src="Struts 2的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/ExpandedBlockStart.gif" 
align=top><IMG id=Codehighlighter1_141_333_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; Codehighlighter1_141_333_Closed_Text.style.display='none'; Codehighlighter1_141_333_Open_Image.style.display='inline'; Codehighlighter1_141_333_Open_Text.style.display='inline';" 
src="Struts 2的基石——拦截器(Interceptor) - 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">AuthorizatedAccess </SPAN><SPAN 
style="COLOR: #0000ff">extends</SPAN> <SPAN style="COLOR: #000000">ActionSupport 
</SPAN><SPAN style="COLOR: #0000ff">implements</SPAN> <SPAN 
style="COLOR: #000000">RoleAware </SPAN><SPAN 
id=Codehighlighter1_141_333_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的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/dot.gif"> 
</SPAN><SPAN id=Codehighlighter1_141_333_Open_Text><SPAN 
style="COLOR: #000000">{<BR><IMG 
src="Struts 2的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/InBlock.gif" 
align=top> &nbsp; &nbsp;</SPAN> <SPAN style="COLOR: #0000ff">private</SPAN> 
<SPAN style="COLOR: #000000">String role;<BR><IMG 
src="Struts 2的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/InBlock.gif" 
align=top> &nbsp; &nbsp;<BR><IMG id=Codehighlighter1_201_224_Open_Image 
onclick="this.style.display='none'; Codehighlighter1_201_224_Open_Text.style.display='none'; Codehighlighter1_201_224_Closed_Image.style.display='inline'; Codehighlighter1_201_224_Closed_Text.style.display='inline';" 
src="Struts 2的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/ExpandedSubBlockStart.gif" 
align=top><IMG id=Codehighlighter1_201_224_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; Codehighlighter1_201_224_Closed_Text.style.display='none'; Codehighlighter1_201_224_Open_Image.style.display='inline'; Codehighlighter1_201_224_Open_Text.style.display='inline';" 
src="Struts 2的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/ContractedSubBlock.gif" 
align=top> &nbsp; &nbsp;</SPAN> <SPAN style="COLOR: #0000ff">public</SPAN> <SPAN 
style="COLOR: #000000"></SPAN><SPAN style="COLOR: #0000ff">void</SPAN> <SPAN 
style="COLOR: #000000">setRole(String role) </SPAN><SPAN 
id=Codehighlighter1_201_224_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的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/dot.gif"> 
</SPAN><SPAN id=Codehighlighter1_201_224_Open_Text><SPAN 
style="COLOR: #000000">{<BR><IMG 
src="Struts 2的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/InBlock.gif" 
align=top> &nbsp; &nbsp; &nbsp; &nbsp;</SPAN> <SPAN 
style="COLOR: #0000ff">this</SPAN> <SPAN style="COLOR: #000000">.role 
</SPAN><SPAN style="COLOR: #000000">=</SPAN> <SPAN 
style="COLOR: #000000">role;<BR><IMG 
src="Struts 2的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/ExpandedSubBlockEnd.gif" 
align=top> &nbsp; &nbsp;}</SPAN> </SPAN><SPAN style="COLOR: #000000"><BR><IMG 
src="Struts 2的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/InBlock.gif" 
align=top> &nbsp; &nbsp;<BR><IMG id=Codehighlighter1_253_271_Open_Image 
onclick="this.style.display='none'; Codehighlighter1_253_271_Open_Text.style.display='none'; Codehighlighter1_253_271_Closed_Image.style.display='inline'; Codehighlighter1_253_271_Closed_Text.style.display='inline';" 
src="Struts 2的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/ExpandedSubBlockStart.gif" 
align=top><IMG id=Codehighlighter1_253_271_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; Codehighlighter1_253_271_Closed_Text.style.display='none'; Codehighlighter1_253_271_Open_Image.style.display='inline'; Codehighlighter1_253_271_Open_Text.style.display='inline';" 
src="Struts 2的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/ContractedSubBlock.gif" 
align=top> &nbsp; &nbsp;</SPAN> <SPAN style="COLOR: #0000ff">public</SPAN> <SPAN 
style="COLOR: #000000">String getRole() </SPAN><SPAN 
id=Codehighlighter1_253_271_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的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/dot.gif"> 
</SPAN><SPAN id=Codehighlighter1_253_271_Open_Text><SPAN 
style="COLOR: #000000">{<BR><IMG 
src="Struts 2的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/InBlock.gif" 
align=top> &nbsp; &nbsp; &nbsp; &nbsp;</SPAN> <SPAN 
style="COLOR: #0000ff">return</SPAN> <SPAN style="COLOR: #000000">role;<BR><IMG 
src="Struts 2的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/ExpandedSubBlockEnd.gif" 
align=top> &nbsp; &nbsp;}</SPAN> </SPAN><SPAN style="COLOR: #000000"><BR><IMG 
src="Struts 2的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/InBlock.gif" 
align=top> <BR><IMG 
src="Struts 2的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/InBlock.gif" 
align=top> &nbsp; &nbsp;@Override<BR><IMG id=Codehighlighter1_310_331_Open_Image 
onclick="this.style.display='none'; Codehighlighter1_310_331_Open_Text.style.display='none'; Codehighlighter1_310_331_Closed_Image.style.display='inline'; Codehighlighter1_310_331_Closed_Text.style.display='inline';" 
src="Struts 2的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/ExpandedSubBlockStart.gif" 
align=top><IMG id=Codehighlighter1_310_331_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; Codehighlighter1_310_331_Closed_Text.style.display='none'; Codehighlighter1_310_331_Open_Image.style.display='inline'; Codehighlighter1_310_331_Open_Text.style.display='inline';" 
src="Struts 2的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/ContractedSubBlock.gif" 
align=top> &nbsp; &nbsp;</SPAN> <SPAN style="COLOR: #0000ff">public</SPAN> <SPAN 
style="COLOR: #000000">String execute() </SPAN><SPAN 
id=Codehighlighter1_310_331_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的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/dot.gif"> 
</SPAN><SPAN id=Codehighlighter1_310_331_Open_Text><SPAN 
style="COLOR: #000000">{<BR><IMG 
src="Struts 2的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/InBlock.gif" 
align=top> &nbsp; &nbsp; &nbsp; &nbsp;</SPAN> <SPAN 
style="COLOR: #0000ff">return</SPAN> <SPAN 
style="COLOR: #000000">SUCCESS;<BR><IMG 
src="Struts 2的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/ExpandedSubBlockEnd.gif" 
align=top> &nbsp; &nbsp;}</SPAN> </SPAN><SPAN style="COLOR: #000000"><BR><IMG 
src="Struts 2的基石——拦截器(Interceptor) - Max On Java - BlogJava.files/ExpandedBlockEnd.gif" 
align=top>}</SPAN> </SPAN></DIV>
<P>以下是ShowUser.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 
&nbsp;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: #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></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN> <SPAN 
style="COLOR: #800000">html</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">Authorizated User</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">h1</SPAN> <SPAN style="COLOR: #0000ff">&gt;</SPAN> <SPAN 
style="COLOR: #000000">Your role is: </SPAN><SPAN 
style="COLOR: #0000ff">&lt;</SPAN> <SPAN style

⌨️ 快捷键说明

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