?? 轉換器(converter)——struts 2_0中的魔術師 - max on java - blogjava.htm
字號:
<SPAN style="COLOR: #ff0000">uri</SPAN> <SPAN
style="COLOR: #0000ff">="/struts-tags"</SPAN> <SPAN
style="COLOR: #ff0000">%</SPAN> <SPAN style="COLOR: #0000ff">></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">Hello World</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">s:form </SPAN><SPAN style="COLOR: #ff0000">action</SPAN>
<SPAN style="COLOR: #0000ff">="HelloWorld"</SPAN> <SPAN
style="COLOR: #ff0000">theme</SPAN> <SPAN
style="COLOR: #0000ff">="simple"</SPAN> <SPAN style="COLOR: #0000ff">></SPAN>
<SPAN style="COLOR: #000000"> <BR>
Locale: </SPAN><SPAN style="COLOR: #0000ff"><</SPAN>
<SPAN style="COLOR: #800000">s:textfield </SPAN><SPAN
style="COLOR: #ff0000">name</SPAN> <SPAN style="COLOR: #0000ff">="loc"</SPAN>
<SPAN style="COLOR: #ff0000"></SPAN><SPAN style="COLOR: #0000ff">/></SPAN>
<SPAN style="COLOR: #ff0000">&nbsp;</SPAN> <SPAN
style="COLOR: #0000ff"><</SPAN> <SPAN style="COLOR: #800000">s:submit
</SPAN><SPAN style="COLOR: #0000ff">/></SPAN> <SPAN
style="COLOR: #000000"><BR> </SPAN><SPAN
style="COLOR: #0000ff"></</SPAN> <SPAN style="COLOR: #800000">s:form</SPAN>
<SPAN style="COLOR: #0000ff">></SPAN> <SPAN style="COLOR: #000000">
<BR> </SPAN><SPAN style="COLOR: #0000ff"><</SPAN> <SPAN
style="COLOR: #800000">h2</SPAN> <SPAN style="COLOR: #0000ff">><</SPAN>
<SPAN style="COLOR: #800000">s:property </SPAN><SPAN
style="COLOR: #ff0000">value</SPAN> <SPAN style="COLOR: #0000ff">="msg"</SPAN>
<SPAN style="COLOR: #ff0000"></SPAN><SPAN
style="COLOR: #0000ff">/></</SPAN> <SPAN style="COLOR: #800000">h2</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">html</SPAN>
<SPAN style="COLOR: #0000ff">></SPAN> </DIV>
<P>接下來,在源代碼文件夾的tutorial包中新建LocaleConverter.java文件,代碼如下:<BR></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="轉換器(Converter)——Struts 2_0中的魔術師 - Max On Java - BlogJava.files/None.gif"
align=top> <SPAN style="COLOR: #0000ff">package</SPAN> <SPAN
style="COLOR: #000000">tutorial;<BR><IMG
src="轉換器(Converter)——Struts 2_0中的魔術師 - Max On Java - BlogJava.files/None.gif"
align=top><BR><IMG
src="轉換器(Converter)——Struts 2_0中的魔術師 - Max On Java - BlogJava.files/None.gif"
align=top></SPAN> <SPAN style="COLOR: #0000ff">import</SPAN> <SPAN
style="COLOR: #000000">java.util.Locale;<BR><IMG
src="轉換器(Converter)——Struts 2_0中的魔術師 - Max On Java - BlogJava.files/None.gif"
align=top></SPAN> <SPAN style="COLOR: #0000ff">import</SPAN> <SPAN
style="COLOR: #000000">java.util.Map;<BR><IMG
src="轉換器(Converter)——Struts 2_0中的魔術師 - Max On Java - BlogJava.files/None.gif"
align=top><BR><IMG id=Codehighlighter1_130_478_Open_Image
onclick="this.style.display='none'; Codehighlighter1_130_478_Open_Text.style.display='none'; Codehighlighter1_130_478_Closed_Image.style.display='inline'; Codehighlighter1_130_478_Closed_Text.style.display='inline';"
src="轉換器(Converter)——Struts 2_0中的魔術師 - Max On Java - BlogJava.files/ExpandedBlockStart.gif"
align=top><IMG id=Codehighlighter1_130_478_Closed_Image style="DISPLAY: none"
onclick="this.style.display='none'; Codehighlighter1_130_478_Closed_Text.style.display='none'; Codehighlighter1_130_478_Open_Image.style.display='inline'; Codehighlighter1_130_478_Open_Text.style.display='inline';"
src="轉換器(Converter)——Struts 2_0中的魔術師 - 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">LocaleConverter </SPAN><SPAN
style="COLOR: #0000ff">extends</SPAN> <SPAN
style="COLOR: #000000">ognl.DefaultTypeConverter </SPAN><SPAN
id=Codehighlighter1_130_478_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="轉換器(Converter)——Struts 2_0中的魔術師 - Max On Java - BlogJava.files/dot.gif">
</SPAN><SPAN id=Codehighlighter1_130_478_Open_Text><SPAN
style="COLOR: #000000">{<BR><IMG
src="轉換器(Converter)——Struts 2_0中的魔術師 - Max On Java - BlogJava.files/InBlock.gif"
align=top> @Override<BR><IMG id=Codehighlighter1_212_476_Open_Image
onclick="this.style.display='none'; Codehighlighter1_212_476_Open_Text.style.display='none'; Codehighlighter1_212_476_Closed_Image.style.display='inline'; Codehighlighter1_212_476_Closed_Text.style.display='inline';"
src="轉換器(Converter)——Struts 2_0中的魔術師 - Max On Java - BlogJava.files/ExpandedSubBlockStart.gif"
align=top><IMG id=Codehighlighter1_212_476_Closed_Image style="DISPLAY: none"
onclick="this.style.display='none'; Codehighlighter1_212_476_Closed_Text.style.display='none'; Codehighlighter1_212_476_Open_Image.style.display='inline'; Codehighlighter1_212_476_Open_Text.style.display='inline';"
src="轉換器(Converter)——Struts 2_0中的魔術師 - Max On Java - BlogJava.files/ContractedSubBlock.gif"
align=top> </SPAN> <SPAN style="COLOR: #0000ff">public</SPAN> <SPAN
style="COLOR: #000000">Object convertValue(Map context, Object value, Class
toType) </SPAN><SPAN id=Codehighlighter1_212_476_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="轉換器(Converter)——Struts 2_0中的魔術師 - Max On Java - BlogJava.files/dot.gif">
</SPAN><SPAN id=Codehighlighter1_212_476_Open_Text><SPAN
style="COLOR: #000000">{<BR><IMG id=Codehighlighter1_243_356_Open_Image
onclick="this.style.display='none'; Codehighlighter1_243_356_Open_Text.style.display='none'; Codehighlighter1_243_356_Closed_Image.style.display='inline'; Codehighlighter1_243_356_Closed_Text.style.display='inline';"
src="轉換器(Converter)——Struts 2_0中的魔術師 - Max On Java - BlogJava.files/ExpandedSubBlockStart.gif"
align=top><IMG id=Codehighlighter1_243_356_Closed_Image style="DISPLAY: none"
onclick="this.style.display='none'; Codehighlighter1_243_356_Closed_Text.style.display='none'; Codehighlighter1_243_356_Open_Image.style.display='inline'; Codehighlighter1_243_356_Open_Text.style.display='inline';"
src="轉換器(Converter)——Struts 2_0中的魔術師 - Max On Java - BlogJava.files/ContractedSubBlock.gif"
align=top> </SPAN> <SPAN
style="COLOR: #0000ff">if</SPAN> <SPAN style="COLOR: #000000">(toType
</SPAN><SPAN style="COLOR: #000000">==</SPAN> <SPAN
style="COLOR: #000000">Locale.</SPAN> <SPAN style="COLOR: #0000ff">class</SPAN>
<SPAN style="COLOR: #000000">) </SPAN><SPAN
id=Codehighlighter1_243_356_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="轉換器(Converter)——Struts 2_0中的魔術師 - Max On Java - BlogJava.files/dot.gif">
</SPAN><SPAN id=Codehighlighter1_243_356_Open_Text><SPAN
style="COLOR: #000000">{<BR><IMG
src="轉換器(Converter)——Struts 2_0中的魔術師 - Max On Java - BlogJava.files/InBlock.gif"
align=top> String locale </SPAN><SPAN
style="COLOR: #000000">=</SPAN> <SPAN style="COLOR: #000000">((String[])
value)[</SPAN> <SPAN style="COLOR: #000000">0</SPAN> <SPAN
style="COLOR: #000000">];<BR><IMG
src="轉換器(Converter)——Struts 2_0中的魔術師 - Max On Java - BlogJava.files/InBlock.gif"
align=top> </SPAN> <SPAN
style="COLOR: #0000ff">return</SPAN> <SPAN style="COLOR: #000000"></SPAN><SPAN
style="COLOR: #0000ff">new</SPAN> <SPAN
style="COLOR: #000000">Locale(locale.substring(</SPAN> <SPAN
style="COLOR: #000000">0</SPAN> <SPAN style="COLOR: #000000">, </SPAN><SPAN
style="COLOR: #000000">2</SPAN> <SPAN style="COLOR: #000000">),
locale.substring(</SPAN> <SPAN style="COLOR: #000000">3</SPAN> <SPAN
style="COLOR: #000000">));<BR><IMG id=Codehighlighter1_390_458_Open_Image
onclick="this.style.display='none'; Codehighlighter1_390_458_Open_Text.style.display='none'; Codehighlighter1_390_458_Closed_Image.style.display='inline'; Codehighlighter1_390_458_Closed_Text.style.display='inline';"
src="轉換器(Converter)——Struts 2_0中的魔術師 - Max On Java - BlogJava.files/ExpandedSubBlockStart.gif"
align=top><IMG id=Codehighlighter1_390_458_Closed_Image style="DISPLAY: none"
onclick="this.style.display='none'; Codehighlighter1_390_458_Closed_Text.style.display='none'; Codehighlighter1_390_458_Open_Image.style.display='inline'; Codehighlighter1_390_458_Open_Text.style.display='inline';"
src="轉換器(Converter)——Struts 2_0中的魔術師 - Max On Java - BlogJava.files/ContractedSubBlock.gif"
align=top> }</SPAN> </SPAN><SPAN
style="COLOR: #000000"></SPAN><SPAN style="COLOR: #0000ff">else</SPAN> <SPAN
style="COLOR: #000000"></SPAN><SPAN style="COLOR: #0000ff">if</SPAN> <SPAN
style="COLOR: #000000">(toType </SPAN><SPAN style="COLOR: #000000">==</SPAN>
<SPAN style="COLOR: #000000">String.</SPAN> <SPAN
style="COLOR: #0000ff">class</SPAN> <SPAN style="COLOR: #000000">) </SPAN><SPAN
id=Codehighlighter1_390_458_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="轉換器(Converter)——Struts 2_0中的魔術師 - Max On Java - BlogJava.files/dot.gif">
</SPAN><SPAN id=Codehighlighter1_390_458_Open_Text><SPAN
style="COLOR: #000000">{<BR><IMG
src="轉換器(Converter)——Struts 2_0中的魔術師 - Max On Java - BlogJava.files/InBlock.gif"
align=top> Locale locale </SPAN><SPAN
style="COLOR: #000000">=</SPAN> <SPAN style="COLOR: #000000">(Locale)
value;<BR><IMG
src="轉換器(Converter)——Struts 2_0中的魔術師 - Max On Java - BlogJava.files/InBlock.gif"
align=top> </SPAN> <SPAN
style="COLOR: #0000ff">return</SPAN> <SPAN
style="COLOR: #000000">locale.toString();<BR><IMG
src="轉換器(Converter)——Struts 2_0中的魔術師 - Max On Java - BlogJava.files/ExpandedSubBlockEnd.gif"
align=top> }</SPAN> </SPAN><SPAN
style="COLOR: #000000"><BR><IMG
src="轉換器(Converter)——Struts 2_0中的魔術師 - Max On Java - BlogJava.files/InBlock.gif"
align=top> </SPAN> <SPAN
style="COLOR: #0000ff">return</SPAN> <SPAN style="COLOR: #000000"></SPAN><SPAN
style="COLOR: #0000ff">null</SPAN> <SPAN style="COLOR: #000000">;<BR><IMG
src="轉換器(Converter)——Struts 2_0中的魔術師 - Max On Java - BlogJava.files/ExpandedSubBlockEnd.gif"
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -