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

📄 struts 2_0的action讲解 - max on java - blogjava.htm

📁 struts2标签的详细解释说明教程
💻 HTM
📖 第 1 页 / 共 5 页
字号:
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">Login</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></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN 
style="COLOR: #800000">s:form </SPAN><SPAN 
style="COLOR: #ff0000">action</SPAN><SPAN 
style="COLOR: #0000ff">="Login"</SPAN><SPAN style="COLOR: #ff0000"> 
method</SPAN><SPAN style="COLOR: #0000ff">="POST"</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">s:textfield </SPAN><SPAN 
style="COLOR: #ff0000">name</SPAN><SPAN 
style="COLOR: #0000ff">="name"</SPAN><SPAN style="COLOR: #ff0000"> 
label</SPAN><SPAN style="COLOR: #0000ff">="User name"</SPAN><SPAN 
style="COLOR: #ff0000"></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">s:password 
</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN 
style="COLOR: #0000ff">="password"</SPAN><SPAN style="COLOR: #ff0000"> 
label</SPAN><SPAN style="COLOR: #0000ff">="Password"</SPAN><SPAN 
style="COLOR: #ff0000"></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">s:submit 
</SPAN><SPAN style="COLOR: #ff0000">value</SPAN><SPAN 
style="COLOR: #0000ff">="Submit"</SPAN><SPAN 
style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN 
style="COLOR: #0000ff">&lt;/</SPAN><SPAN 
style="COLOR: #800000">s:form</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></SPAN><SPAN 
style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">html</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN></DIV><SPAN 
style="FONT-SIZE: smaller; FONT-STYLE: italic">例4 Login.jsp</SPAN><BR><BR>
<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">&lt;</SPAN><SPAN style="COLOR: #800000">action 
</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN 
style="COLOR: #0000ff">="Login"</SPAN><SPAN style="COLOR: #ff0000"> 
class</SPAN><SPAN style="COLOR: #0000ff">="tutorial.Login"</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">result</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN 
style="COLOR: #000000">/HelloWorld.jsp</SPAN><SPAN 
style="COLOR: #0000ff">&lt;/</SPAN><SPAN 
style="COLOR: #800000">result</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN 
style="COLOR: #0000ff">&lt;/</SPAN><SPAN 
style="COLOR: #800000">action</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN></DIV><SPAN 
style="FONT-SIZE: smaller; FONT-STYLE: italic">例4 classes/struts.xml中Login 
Action的配置</SPAN><BR><BR>运行Tomcat,在浏览器地址栏中键入<A 
href="http://localhost:8080/Struts2_Action/Login.jsp">http://localhost:8080/Struts2_Action/Login.jsp</A>,出现如图4所示页面。<BR><BR><IMG 
alt="图4 Login.jsp输出页面" 
src="Struts 2_0的Action讲解 - Max On Java - BlogJava.files/r_img_4.gif"><BR><SPAN 
style="FONT-SIZE: smaller; FONT-STYLE: italic">图4 
Login.jsp输出页面</SPAN><BR><BR>分别在User 
name中输入“max”和“secret”,点击“Submit”按钮,出现如图5所示页面。<BR><BR><IMG alt="图5 Login成功页面" 
src="Struts 2_0的Action讲解 - Max On Java - BlogJava.files/r_img_5.gif"><BR><SPAN 
style="FONT-STYLE: italic"></SPAN><EM><SPAN style="FONT-SIZE: smaller">图5 
Login成功页面</SPAN></EM><BR><BR>在浏览器地址栏中键入<A 
href="http://localhost:8080/Struts2_Action/Login.jsp">http://localhost:8080/Struts2_Action/Login.jsp</A>,分别在User 
name中输入“Scott”和“password”,点击“Submit”按钮,出现如图6所示页面。<BR><BR><IMG alt="图6 Login失败页面" 
src="Struts 2_0的Action讲解 - Max On Java - BlogJava.files/r_img_6.gif"><BR><SPAN 
style="FONT-SIZE: smaller; FONT-STYLE: italic">图6 Login失败页面</SPAN>&nbsp; 
<P>Struts 
2.0更厉害的是支持更高级的POJO访问,如user.getPassword()。我们可以用另一写法实现例4。首先,将name和password从Login类中分离出来,到新建类User中。这样对我们开发多层系统尤其有用。它可以使系统结构更清晰。</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_0的Action讲解 - 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_0的Action讲解 - Max On Java - BlogJava.files/None.gif" 
align=top><BR><IMG 
src="Struts 2_0的Action讲解 - 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的Action讲解 - Max On Java - BlogJava.files/None.gif" 
align=top><BR><IMG id=Codehighlighter1_108_550_Open_Image 
onclick="this.style.display='none'; Codehighlighter1_108_550_Open_Text.style.display='none'; Codehighlighter1_108_550_Closed_Image.style.display='inline'; Codehighlighter1_108_550_Closed_Text.style.display='inline';" 
src="Struts 2_0的Action讲解 - Max On Java - BlogJava.files/ExpandedBlockStart.gif" 
align=top><IMG id=Codehighlighter1_108_550_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; Codehighlighter1_108_550_Closed_Text.style.display='none'; Codehighlighter1_108_550_Open_Image.style.display='inline'; Codehighlighter1_108_550_Open_Text.style.display='inline';" 
src="Struts 2_0的Action讲解 - 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"> LoginX </SPAN><SPAN 
style="COLOR: #0000ff">extends</SPAN><SPAN style="COLOR: #000000"> ActionSupport 
</SPAN><SPAN id=Codehighlighter1_108_550_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的Action讲解 - Max On Java - BlogJava.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_108_550_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
src="Struts 2_0的Action讲解 - Max On Java - BlogJava.files/InBlock.gif" align=top> 
&nbsp; &nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN 
style="COLOR: #000000"> User user;<BR><IMG 
src="Struts 2_0的Action讲解 - Max On Java - BlogJava.files/InBlock.gif" align=top> 
&nbsp; &nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN 
style="COLOR: #000000"> String message;<BR><IMG 
src="Struts 2_0的Action讲解 - Max On Java - BlogJava.files/InBlock.gif" align=top> 
&nbsp; &nbsp;<BR><IMG id=Codehighlighter1_189_212_Open_Image 
onclick="this.style.display='none'; Codehighlighter1_189_212_Open_Text.style.display='none'; Codehighlighter1_189_212_Closed_Image.style.display='inline'; Codehighlighter1_189_212_Closed_Text.style.display='inline';" 
src="Struts 2_0的Action讲解 - Max On Java - BlogJava.files/ExpandedSubBlockStart.gif" 
align=top><IMG id=Codehighlighter1_189_212_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; Codehighlighter1_189_212_Closed_Text.style.display='none'; Codehighlighter1_189_212_Open_Image.style.display='inline'; Codehighlighter1_189_212_Open_Text.style.display='inline';" 
src="Struts 2_0的Action讲解 - 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"> setUser(User user) </SPAN><SPAN 
id=Codehighlighter1_189_212_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的Action讲解 - Max On Java - BlogJava.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_189_212_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
src="Struts 2_0的Action讲解 - Max On Java - BlogJava.files/InBlock.gif" align=top> 
&nbsp; &nbsp; &nbsp; &nbsp;</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN 
style="COLOR: #000000">.user </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN 
style="COLOR: #000000"> user;<BR><IMG 
src="Struts 2_0的Action讲解 - Max On Java - BlogJava.files/ExpandedSubBlockEnd.gif" 
align=top> &nbsp; &nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG 
src="Struts 2_0的Action讲解 - Max On Java - BlogJava.files/InBlock.gif" align=top> 
&nbsp; &nbsp;<BR><IMG id=Codehighlighter1_239_257_Open_Image 
onclick="this.style.display='none'; Codehighlighter1_239_257_Open_Text.style.display='none'; Codehighlighter1_239_257_Closed_Image.style.display='inline'; Codehighlighter1_239_257_Closed_Text.style.display='inline';" 
src="Struts 2_0的Action讲解 - Max On Java - BlogJava.files/ExpandedSubBlockStart.gif" 
align=top><IMG id=Codehighlighter1_239_257_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; Codehighlighter1_239_257_Closed_Text.style.display='none'; Codehighlighter1_239_257_Open_Image.style.display='inline'; Codehighlighter1_239_257_Open_Text.style.display='inline';" 
src="Struts 2_0的Action讲解 - Max On Java - BlogJava.files/ContractedSubBlock.gif" 
align=top> &nbsp; &nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN 
style="COLOR: #000000"> User getUser() </SPAN><SPAN 
id=Codehighlighter1_239_257_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的Action讲解 - Max On Java - BlogJava.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_239_257_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
src="Struts 2_0的Action讲解 - Max On Java - BlogJava.files/InBlock.gif" align=top> 
&nbsp; &nbsp; &nbsp; &nbsp;</SPAN><SPAN 
style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000"> user;<BR><IMG 
src="Struts 2_0的Action讲解 - Max On Java - BlogJava.files/ExpandedSubBlockEnd.gif" 
align=top> &nbsp; &nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG 
src="Struts 2_0的Action讲解 - Max On Java - BlogJava.files/InBlock.gif" align=top> 
&nbsp; &nbsp;<BR><IMG id=Codehighlighter1_289_310_Open_Image 
onclick="this.style.display='none'; Codehighlighter1_289_310_Open_Text.style.display='none'; Codehighlighter1_289_310_Closed_Image.style.display='inline'; Codehighlighter1_289_310_Closed_Text.style.display='inline';" 
src="Struts 2_0的Action讲解 - Max On Java - BlogJava.files/ExpandedSubBlockStart.gif" 
align=top><IMG id=Codehighlighter1_289_310_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; Codehighlighter1_289_310_Closed_Text.style.display='none'; Codehighlighter1_289_310_Open_Image.style.display='inline'; Codehighlighter1_289_310_Open_Text.style.display='inline';" 
src="Struts 2_0的Action讲解 - Max On Java - BlogJava.files/Contract

⌨️ 快捷键说明

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