?? struts 2的基石——攔截器(interceptor) - max on java - blogjava.htm
字號:
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> </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> </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> <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> </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
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> </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> }</SPAN> </SPAN><SPAN style="COLOR: #000000"><BR><IMG
src="Struts 2的基石——攔截器(Interceptor) - Max On Java - BlogJava.files/InBlock.gif"
align=top> <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> </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> </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> }</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> @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> </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> </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> }</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"><%</SPAN> <SPAN
style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">@ page
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">%></SPAN> <SPAN
style="COLOR: #000000"><BR></SPAN><SPAN
style="COLOR: #000000; BACKGROUND-COLOR: #ffff00"><%</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">%></SPAN> <SPAN
style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff"><</SPAN> <SPAN
style="COLOR: #800000">html</SPAN> <SPAN style="COLOR: #0000ff">></SPAN>
<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff"><</SPAN>
<SPAN style="COLOR: #800000">head</SPAN> <SPAN
style="COLOR: #0000ff">></SPAN> <SPAN style="COLOR: #000000"><BR>
</SPAN><SPAN style="COLOR: #0000ff"><</SPAN> <SPAN
style="COLOR: #800000">title</SPAN> <SPAN style="COLOR: #0000ff">></SPAN>
<SPAN style="COLOR: #000000">Authorizated User</SPAN> <SPAN
style="COLOR: #0000ff"></</SPAN> <SPAN style="COLOR: #800000">title</SPAN>
<SPAN style="COLOR: #0000ff">></SPAN> <SPAN
style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff"></</SPAN>
<SPAN style="COLOR: #800000">head</SPAN> <SPAN
style="COLOR: #0000ff">></SPAN> <SPAN style="COLOR: #000000"><BR></SPAN><SPAN
style="COLOR: #0000ff"><</SPAN> <SPAN style="COLOR: #800000">body</SPAN>
<SPAN style="COLOR: #0000ff">></SPAN> <SPAN style="COLOR: #000000"><BR>
</SPAN><SPAN style="COLOR: #0000ff"><</SPAN> <SPAN
style="COLOR: #800000">h1</SPAN> <SPAN style="COLOR: #0000ff">></SPAN> <SPAN
style="COLOR: #000000">Your role is: </SPAN><SPAN
style="COLOR: #0000ff"><</SPAN> <SPAN style
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -