📄 在struts 2_0中实现表单数据校验(validation) - max on java - blogjava.htm
字号:
src="在Struts 2_0中实现表单数据校验(Validation) - Max On Java - BlogJava.files/None.gif"
align=top><BR><IMG
src="在Struts 2_0中实现表单数据校验(Validation) - 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_0中实现表单数据校验(Validation) - Max On Java - BlogJava.files/None.gif"
align=top><BR><IMG id=Codehighlighter1_118_380_Open_Image
onclick="this.style.display='none'; Codehighlighter1_118_380_Open_Text.style.display='none'; Codehighlighter1_118_380_Closed_Image.style.display='inline'; Codehighlighter1_118_380_Closed_Text.style.display='inline';"
src="在Struts 2_0中实现表单数据校验(Validation) - Max On Java - BlogJava.files/ExpandedBlockStart.gif"
align=top><IMG id=Codehighlighter1_118_380_Closed_Image style="DISPLAY: none"
onclick="this.style.display='none'; Codehighlighter1_118_380_Closed_Text.style.display='none'; Codehighlighter1_118_380_Open_Image.style.display='inline'; Codehighlighter1_118_380_Open_Text.style.display='inline';"
src="在Struts 2_0中实现表单数据校验(Validation) - 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">ValidationAction </SPAN><SPAN
style="COLOR: #0000ff">extends</SPAN> <SPAN style="COLOR: #000000">ActionSupport
</SPAN><SPAN id=Codehighlighter1_118_380_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_0中实现表单数据校验(Validation) - Max On Java - BlogJava.files/dot.gif">
</SPAN><SPAN id=Codehighlighter1_118_380_Open_Text><SPAN
style="COLOR: #000000">{<BR><IMG
src="在Struts 2_0中实现表单数据校验(Validation) - Max On Java - BlogJava.files/InBlock.gif"
align=top> </SPAN> <SPAN style="COLOR: #0000ff">private</SPAN>
<SPAN style="COLOR: #000000">String reqiuredString;<BR><IMG
src="在Struts 2_0中实现表单数据校验(Validation) - Max On Java - BlogJava.files/InBlock.gif"
align=top><BR><IMG id=Codehighlighter1_188_216_Open_Image
onclick="this.style.display='none'; Codehighlighter1_188_216_Open_Text.style.display='none'; Codehighlighter1_188_216_Closed_Image.style.display='inline'; Codehighlighter1_188_216_Closed_Text.style.display='inline';"
src="在Struts 2_0中实现表单数据校验(Validation) - Max On Java - BlogJava.files/ExpandedSubBlockStart.gif"
align=top><IMG id=Codehighlighter1_188_216_Closed_Image style="DISPLAY: none"
onclick="this.style.display='none'; Codehighlighter1_188_216_Closed_Text.style.display='none'; Codehighlighter1_188_216_Open_Image.style.display='inline'; Codehighlighter1_188_216_Open_Text.style.display='inline';"
src="在Struts 2_0中实现表单数据校验(Validation) - Max On Java - BlogJava.files/ContractedSubBlock.gif"
align=top> </SPAN> <SPAN style="COLOR: #0000ff">public</SPAN> <SPAN
style="COLOR: #000000">String getReqiuredString() </SPAN><SPAN
id=Codehighlighter1_188_216_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_0中实现表单数据校验(Validation) - Max On Java - BlogJava.files/dot.gif">
</SPAN><SPAN id=Codehighlighter1_188_216_Open_Text><SPAN
style="COLOR: #000000">{<BR><IMG
src="在Struts 2_0中实现表单数据校验(Validation) - Max On Java - BlogJava.files/InBlock.gif"
align=top> </SPAN> <SPAN
style="COLOR: #0000ff">return</SPAN> <SPAN
style="COLOR: #000000">reqiuredString;<BR><IMG
src="在Struts 2_0中实现表单数据校验(Validation) - Max On Java - BlogJava.files/ExpandedSubBlockEnd.gif"
align=top> }</SPAN> </SPAN><SPAN style="COLOR: #000000"><BR><IMG
src="在Struts 2_0中实现表单数据校验(Validation) - Max On Java - BlogJava.files/InBlock.gif"
align=top> <BR><IMG id=Codehighlighter1_273_316_Open_Image
onclick="this.style.display='none'; Codehighlighter1_273_316_Open_Text.style.display='none'; Codehighlighter1_273_316_Closed_Image.style.display='inline'; Codehighlighter1_273_316_Closed_Text.style.display='inline';"
src="在Struts 2_0中实现表单数据校验(Validation) - Max On Java - BlogJava.files/ExpandedSubBlockStart.gif"
align=top> <IMG id=Codehighlighter1_273_316_Closed_Image style="DISPLAY: none"
onclick="this.style.display='none'; Codehighlighter1_273_316_Closed_Text.style.display='none'; Codehighlighter1_273_316_Open_Image.style.display='inline'; Codehighlighter1_273_316_Open_Text.style.display='inline';"
src="在Struts 2_0中实现表单数据校验(Validation) - 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">setReqiuredString(String reqiuredString) </SPAN><SPAN
id=Codehighlighter1_273_316_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_0中实现表单数据校验(Validation) - Max On Java - BlogJava.files/dot.gif">
</SPAN><SPAN id=Codehighlighter1_273_316_Open_Text><SPAN
style="COLOR: #000000">{<BR><IMG
src="在Struts 2_0中实现表单数据校验(Validation) - Max On Java - BlogJava.files/InBlock.gif"
align=top> </SPAN> <SPAN
style="COLOR: #0000ff">this</SPAN> <SPAN style="COLOR: #000000">.reqiuredString
</SPAN><SPAN style="COLOR: #000000">=</SPAN> <SPAN
style="COLOR: #000000">reqiuredString;<BR><IMG
src="在Struts 2_0中实现表单数据校验(Validation) - Max On Java - BlogJava.files/ExpandedSubBlockEnd.gif"
align=top> }</SPAN> </SPAN><SPAN style="COLOR: #000000"><BR><IMG
src="在Struts 2_0中实现表单数据校验(Validation) - Max On Java - BlogJava.files/InBlock.gif"
align=top> <BR><IMG
src="在Struts 2_0中实现表单数据校验(Validation) - Max On Java - BlogJava.files/InBlock.gif"
align=top> @Override<BR><IMG id=Codehighlighter1_356_377_Open_Image
onclick="this.style.display='none'; Codehighlighter1_356_377_Open_Text.style.display='none'; Codehighlighter1_356_377_Closed_Image.style.display='inline'; Codehighlighter1_356_377_Closed_Text.style.display='inline';"
src="在Struts 2_0中实现表单数据校验(Validation) - Max On Java - BlogJava.files/ExpandedSubBlockStart.gif"
align=top><IMG id=Codehighlighter1_356_377_Closed_Image style="DISPLAY: none"
onclick="this.style.display='none'; Codehighlighter1_356_377_Closed_Text.style.display='none'; Codehighlighter1_356_377_Open_Image.style.display='inline'; Codehighlighter1_356_377_Open_Text.style.display='inline';"
src="在Struts 2_0中实现表单数据校验(Validation) - 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_356_377_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_0中实现表单数据校验(Validation) - Max On Java - BlogJava.files/dot.gif">
</SPAN><SPAN id=Codehighlighter1_356_377_Open_Text><SPAN
style="COLOR: #000000">{<BR><IMG
src="在Struts 2_0中实现表单数据校验(Validation) - 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_0中实现表单数据校验(Validation) - Max On Java - BlogJava.files/ExpandedSubBlockEnd.gif"
align=top> }</SPAN> </SPAN><SPAN style="COLOR: #000000">
<BR><IMG
src="在Struts 2_0中实现表单数据校验(Validation) - Max On Java - BlogJava.files/ExpandedBlockEnd.gif"
align=top>}</SPAN> </SPAN></DIV>
<P>然后,配置上述所建的Ation,代码片段如下:</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">action
</SPAN><SPAN style="COLOR: #ff0000">name</SPAN> <SPAN
style="COLOR: #0000ff">="ValidationAction"</SPAN> <SPAN
style="COLOR: #ff0000">class</SPAN> <SPAN
style="COLOR: #0000ff">="tutorial.ValidationAction"</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">/Output.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">result </SPAN><SPAN style="COLOR: #ff0000">name</SPAN>
<SPAN style="COLOR: #0000ff">="input"</SPAN> <SPAN
style="COLOR: #0000ff">></SPAN> <SPAN
style="COLOR: #000000">/Input.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> </DIV>
<P>接着,创建Input.jsp和Output.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">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: #008000"><!--</SPAN> <SPAN
style="COLOR: #008000">此标志的作用是引入Struts 2.0的常用的Javascript和CSS </SPAN><SPAN
style="COLOR: #008000">--></SPAN> <SPAN style="COLOR: #000000"><BR>
</SPAN><SPAN style="COLOR: #0000ff"><</SPAN> <SPAN
style="COLOR: #800000">s:head </SPAN><SPAN style="COLOR: #0000ff">/></SPAN>
<SPAN style="COLOR: #000000"><BR></SPAN><SPAN
style="COLOR: #0000ff"></</SPAN> <SPAN style="COLOR: #800000">hea
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -