📄 转换器(converter)——struts 2_0中的魔术师 - max on java - blogjava.htm
字号:
align=top><IMG id=Codehighlighter1_193_592_Closed_Image style="DISPLAY: none"
onclick="this.style.display='none'; Codehighlighter1_193_592_Closed_Text.style.display='none'; Codehighlighter1_193_592_Open_Image.style.display='inline'; Codehighlighter1_193_592_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">HelloWorld </SPAN><SPAN
style="COLOR: #0000ff">extends</SPAN> <SPAN style="COLOR: #000000">ActionSupport
</SPAN><SPAN id=Codehighlighter1_193_592_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_193_592_Open_Text><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">private</SPAN>
<SPAN style="COLOR: #000000">String msg;<BR><IMG
src="转换器(Converter)——Struts 2_0中的魔术师 - Max On Java - BlogJava.files/InBlock.gif"
align=top> </SPAN> <SPAN style="COLOR: #0000ff">private</SPAN>
<SPAN style="COLOR: #000000">Locale loc </SPAN><SPAN
style="COLOR: #000000">=</SPAN> <SPAN style="COLOR: #000000">Locale.US;<BR><IMG
src="转换器(Converter)——Struts 2_0中的魔术师 - Max On Java - BlogJava.files/InBlock.gif"
align=top> <BR><IMG id=Codehighlighter1_280_299_Open_Image
onclick="this.style.display='none'; Codehighlighter1_280_299_Open_Text.style.display='none'; Codehighlighter1_280_299_Closed_Image.style.display='inline'; Codehighlighter1_280_299_Closed_Text.style.display='inline';"
src="转换器(Converter)——Struts 2_0中的魔术师 - Max On Java - BlogJava.files/ExpandedSubBlockStart.gif"
align=top><IMG id=Codehighlighter1_280_299_Closed_Image style="DISPLAY: none"
onclick="this.style.display='none'; Codehighlighter1_280_299_Closed_Text.style.display='none'; Codehighlighter1_280_299_Open_Image.style.display='inline'; Codehighlighter1_280_299_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">String getMsg() </SPAN><SPAN
id=Codehighlighter1_280_299_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_280_299_Open_Text><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">msg;
<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> <BR><IMG id=Codehighlighter1_327_344_Open_Image
onclick="this.style.display='none'; Codehighlighter1_327_344_Open_Text.style.display='none'; Codehighlighter1_327_344_Closed_Image.style.display='inline'; Codehighlighter1_327_344_Closed_Text.style.display='inline';"
src="转换器(Converter)——Struts 2_0中的魔术师 - Max On Java - BlogJava.files/ExpandedSubBlockStart.gif"
align=top><IMG id=Codehighlighter1_327_344_Closed_Image style="DISPLAY: none"
onclick="this.style.display='none'; Codehighlighter1_327_344_Closed_Text.style.display='none'; Codehighlighter1_327_344_Open_Image.style.display='inline'; Codehighlighter1_327_344_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">Locale getLoc() </SPAN><SPAN
id=Codehighlighter1_327_344_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_327_344_Open_Text><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">loc;<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> <BR><IMG id=Codehighlighter1_380_401_Open_Image
onclick="this.style.display='none'; Codehighlighter1_380_401_Open_Text.style.display='none'; Codehighlighter1_380_401_Closed_Image.style.display='inline'; Codehighlighter1_380_401_Closed_Text.style.display='inline';"
src="转换器(Converter)——Struts 2_0中的魔术师 - Max On Java - BlogJava.files/ExpandedSubBlockStart.gif"
align=top><IMG id=Codehighlighter1_380_401_Closed_Image style="DISPLAY: none"
onclick="this.style.display='none'; Codehighlighter1_380_401_Closed_Text.style.display='none'; Codehighlighter1_380_401_Open_Image.style.display='inline'; Codehighlighter1_380_401_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"></SPAN><SPAN style="COLOR: #0000ff">void</SPAN> <SPAN
style="COLOR: #000000">setLoc(Locale loc) </SPAN><SPAN
id=Codehighlighter1_380_401_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_380_401_Open_Text><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">this</SPAN> <SPAN style="COLOR: #000000">.loc
</SPAN><SPAN style="COLOR: #000000">=</SPAN> <SPAN
style="COLOR: #000000">loc;<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> <BR><IMG
src="转换器(Converter)——Struts 2_0中的魔术师 - Max On Java - BlogJava.files/InBlock.gif"
align=top> @Override<BR><IMG id=Codehighlighter1_441_590_Open_Image
onclick="this.style.display='none'; Codehighlighter1_441_590_Open_Text.style.display='none'; Codehighlighter1_441_590_Closed_Image.style.display='inline'; Codehighlighter1_441_590_Closed_Text.style.display='inline';"
src="转换器(Converter)——Struts 2_0中的魔术师 - Max On Java - BlogJava.files/ExpandedSubBlockStart.gif"
align=top><IMG id=Codehighlighter1_441_590_Closed_Image style="DISPLAY: none"
onclick="this.style.display='none'; Codehighlighter1_441_590_Closed_Text.style.display='none'; Codehighlighter1_441_590_Open_Image.style.display='inline'; Codehighlighter1_441_590_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">String execute() </SPAN><SPAN
id=Codehighlighter1_441_590_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_441_590_Open_Text><SPAN
style="COLOR: #000000">{<BR><IMG
src="转换器(Converter)——Struts 2_0中的魔术师 - Max On Java - BlogJava.files/InBlock.gif"
align=top> </SPAN> <SPAN
style="COLOR: #008000">//</SPAN> <SPAN
style="COLOR: #008000">LocalizedTextUtil是Struts
2.0中国际化的工具类,<s:text>标志就是通过调用它实现国际化的</SPAN> <SPAN
style="COLOR: #008000"><BR><IMG
src="转换器(Converter)——Struts 2_0中的魔术师 - Max On Java - BlogJava.files/InBlock.gif"
align=top> </SPAN><SPAN style="COLOR: #000000"> msg
</SPAN><SPAN style="COLOR: #000000">=</SPAN> <SPAN
style="COLOR: #000000">LocalizedTextUtil.findDefaultText(</SPAN> <SPAN
style="COLOR: #000000">"</SPAN> <SPAN style="COLOR: #000000">HelloWorld</SPAN>
<SPAN style="COLOR: #000000">"</SPAN> <SPAN style="COLOR: #000000">,
loc);<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">SUCCESS;<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/ExpandedBlockEnd.gif"
align=top>}</SPAN> </SPAN></DIV>
<P>然后,在源代码文件夹下的struts.xml加入如下代码新建Action:<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"><SPAN
style="COLOR: #0000ff"><</SPAN> <SPAN style="COLOR: #800000">package
</SPAN><SPAN style="COLOR: #ff0000">name</SPAN> <SPAN
style="COLOR: #0000ff">="ConverterDemo"</SPAN> <SPAN
style="COLOR: #ff0000">extends</SPAN> <SPAN
style="COLOR: #0000ff">="struts-default"</SPAN> <SPAN
style="COLOR: #0000ff">></SPAN> <SPAN style="COLOR: #000000"><BR>
</SPAN><SPAN style="COLOR: #0000ff"><</SPAN> <SPAN
style="COLOR: #800000">action </SPAN><SPAN style="COLOR: #ff0000">name</SPAN>
<SPAN style="COLOR: #0000ff">="HelloWorld"</SPAN> <SPAN
style="COLOR: #ff0000">class</SPAN> <SPAN
style="COLOR: #0000ff">="tutorial.HelloWorld"</SPAN> <SPAN
style="COLOR: #0000ff">></SPAN> <SPAN style="COLOR: #000000"><BR>
</SPAN><SPAN style="COLOR: #0000ff"><</SPAN> <SPAN
style="COLOR: #800000">result</SPAN> <SPAN style="COLOR: #0000ff">></SPAN>
<SPAN style="COLOR: #000000">/HelloWorld.jsp</SPAN> <SPAN
style="COLOR: #0000ff"></</SPAN> <SPAN style="COLOR: #800000">result</SPAN>
<SPAN style="COLOR: #0000ff">></SPAN> <SPAN style="COLOR: #000000"><BR>
</SPAN><SPAN style="COLOR: #0000ff"></</SPAN> <SPAN
style="COLOR: #800000">action</SPAN> <SPAN style="COLOR: #0000ff">></SPAN>
<SPAN style="COLOR: #000000"><BR></SPAN><SPAN
style="COLOR: #0000ff"></</SPAN> <SPAN style="COLOR: #800000">package</SPAN>
<SPAN style="COLOR: #0000ff">></SPAN> </DIV>
<P>再在Web文件夹下,新建 HelloWorld.jsp,代码如下:<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"><SPAN
style="COLOR: #0000ff"><</SPAN> <SPAN style="COLOR: #800000">%@ page
</SPAN> <SPAN style="COLOR: #ff0000">contentType</SPAN> <SPAN
style="COLOR: #0000ff">="text/html; charset=UTF-8"</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">%@taglib </SPAN><SPAN
style="COLOR: #ff0000">prefix</SPAN> <SPAN style="COLOR: #0000ff">="s"</SPAN>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -