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

📄 strus 2的新表单标志的使用 - max on java - blogjava.htm

📁 struts2标签的详细解释说明教程
💻 HTM
📖 第 1 页 / 共 5 页
字号:
style="COLOR: #ff0000">&amp;lt;</SPAN><SPAN style="COLOR: #000000">s:token/ 
</SPAN><SPAN style="COLOR: #ff0000">&amp;gt;</SPAN><SPAN 
style="COLOR: #0000ff">&lt;/</SPAN><SPAN 
style="COLOR: #800000">title</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:head 
</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"> &nbsp; &nbsp;<BR>&nbsp; &nbsp; </SPAN><SPAN 
style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">h2</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN 
style="COLOR: #ff0000">&amp;lt;</SPAN><SPAN 
style="COLOR: #000000">s:token/</SPAN><SPAN 
style="COLOR: #ff0000">&amp;gt;</SPAN><SPAN 
style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">h2</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:actionerror </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:form </SPAN><SPAN 
style="COLOR: #ff0000">action</SPAN><SPAN 
style="COLOR: #0000ff">="Token"</SPAN><SPAN style="COLOR: #ff0000"> </SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp; &nbsp; 
&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">="message"</SPAN><SPAN style="COLOR: #ff0000"> 
label</SPAN><SPAN style="COLOR: #0000ff">="Message"</SPAN><SPAN 
style="COLOR: #ff0000"> </SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN 
style="COLOR: #000000"><BR>&nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN 
style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">s:token 
</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN 
style="COLOR: #000000"><BR>&nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN 
style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">s:submit 
</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: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">清单8 WebContent/token.jsp</SPAN> 
<P>JSP也很简单,就是加入&lt;s:token /&gt;标志。接下来是Actoin配置的XML片段:</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">&lt;?</SPAN><SPAN style="COLOR: #ff00ff">xml 
version="1.0" encoding="UTF-8"</SPAN><SPAN 
style="COLOR: #0000ff">?&gt;</SPAN><SPAN 
style="COLOR: #000000"><BR><BR></SPAN><SPAN 
style="COLOR: #0000ff">&lt;!</SPAN><SPAN style="COLOR: #ff00ff">DOCTYPE struts 
PUBLIC<BR>&nbsp; &nbsp; "-//Apache Software Foundation//DTD Struts Configuration 
2.0//EN"<BR>&nbsp; &nbsp; 
"http://struts.apache.org/dtds/struts-2.0.dtd"</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN 
style="COLOR: #000000"><BR><BR></SPAN><SPAN 
style="COLOR: #0000ff">&lt;</SPAN><SPAN 
style="COLOR: #800000">struts</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">package </SPAN><SPAN 
style="COLOR: #ff0000">name</SPAN><SPAN 
style="COLOR: #0000ff">="Struts2_COOL_TAGS_DEMO"</SPAN><SPAN 
style="COLOR: #ff0000"> extends</SPAN><SPAN 
style="COLOR: #0000ff">="struts-default"</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp; &nbsp; 
&nbsp; &nbsp; </SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN 
style="COLOR: #800000">action </SPAN><SPAN 
style="COLOR: #ff0000">name</SPAN><SPAN 
style="COLOR: #0000ff">="Token"</SPAN><SPAN style="COLOR: #ff0000"> 
class</SPAN><SPAN style="COLOR: #0000ff">="tutorial.CoolTagAction"</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN 
style="COLOR: #800000">interceptor-ref </SPAN><SPAN 
style="COLOR: #ff0000">name</SPAN><SPAN 
style="COLOR: #0000ff">="defaultStack"</SPAN><SPAN style="COLOR: #ff0000"> 
</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN 
style="COLOR: #000000"><BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN 
style="COLOR: #800000">interceptor-ref </SPAN><SPAN 
style="COLOR: #ff0000">name</SPAN><SPAN 
style="COLOR: #0000ff">="token"</SPAN><SPAN style="COLOR: #ff0000"> </SPAN><SPAN 
style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN 
style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">result 
</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN 
style="COLOR: #0000ff">="invalid.token"</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN 
style="COLOR: #000000">/token.jsp</SPAN><SPAN 
style="COLOR: #0000ff">&lt;/</SPAN><SPAN 
style="COLOR: #800000">result</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"> &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<BR>&nbsp; 
&nbsp; &nbsp; &nbsp; &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">/token.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>&nbsp; &nbsp; 
&nbsp; &nbsp; </SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN 
style="COLOR: #800000">action</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp; &nbsp; 
&nbsp; &nbsp; </SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN 
style="COLOR: #800000">action </SPAN><SPAN 
style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="*"</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp; &nbsp; 
&nbsp; &nbsp; &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">/{1}.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>&nbsp; &nbsp; 
&nbsp; &nbsp; </SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN 
style="COLOR: #800000">action</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">package</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN 
style="COLOR: #0000ff">&lt;/</SPAN><SPAN 
style="COLOR: #800000">struts</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN></DIV><SPAN 
style="FONT-SIZE: smaller; FONT-STYLE: italic">清单9 src/struts.xml</SPAN> 
<P>以上XML片段值注意的是加入了“token”拦截器和“invalid.token”结果,因为“token”拦截器在会话token与请求token不一致时,将会直接返回“invalid.token”结果。</P>
<P>发布运行应用程序,在浏览器中键入:<A 
href="http://localhost:8080/Struts2_CoolTags/token.jsp">http://localhost:8080/Struts2_CoolTags/token.jsp</A>,出现如下图所示页面:</P>
<P><IMG alt=正常显示的token.jsp页面 
src="Strus 2的新表单标志的使用 - Max On Java - BlogJava.files/r_token1.gif"><BR><SPAN 
style="FONT-SIZE: smaller; FONT-STYLE: italic">清单10 正常显示的token.jsp页面</SPAN></P>
<P>随便填点东西并提交页面,一切正常返回以上页面,然后按“F5”刷新页面,在弹出的对话框中点击“Retry”,出现如下图所示页面:</P>
<P><IMG alt=重复提交出错显示 
src="Strus 2的新表单标志的使用 - Max On Java - BlogJava.files/r_token2.gif"><BR><SPAN 
style="FONT-SIZE: smaller; FONT-STYLE: italic">清单11 重复提交出错显示</SPAN></P>
<H2>4、&lt;s:datetimepicker /&gt;、&lt;s:optiontransferselect 
/&gt;和&lt;s:updownselect /&gt;</H2>
<P>这几个标志的使用相对简单,所以我想小举一例即可,以下是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: #0000ff">&lt;!</SPAN><SPAN style="COLOR: #ff00ff">DOCTYPE html 
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</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: #ff0000">xmlns</SPAN><SPAN 
style="COLOR: #0000ff">="http://www.w3.org/1999/xhtml"</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">Struts 2 Cool Tags - Others</SPAN><SPAN 
style="COLOR: #0000ff">&lt;/</SPAN><SPAN 
style="COLOR: #800000">title</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:head 
</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"> &nbsp; &nbsp;<BR>&nbsp; &nbsp; </SPAN><SPAN 
style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">h2</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN 
style="COLOR: #000000">Others</SPAN><SPAN 
style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">h2</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:form </SPAN><SPAN 
style="COLOR: #ff0000">action</SPAN><SPAN 
style="COLOR: #0000ff">="Store"</SPAN><SPAN style="COLOR: #ff0000"> </SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp; &nbsp; 
&nbsp; &nbsp; </SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN 
style="COLOR: #800000">s:datetimepicker </SPAN><SPAN 
style="COLOR: #ff0000">name</SPAN><SPAN 
style="COLOR: #0000ff">="birthday"</SPAN><SPAN style="COLOR: #ff0000"> 
label</SPAN><SPAN style="COLOR: #0000ff">="Birthday"</SPAN><SPAN 
style="COLOR: #ff0000"> </SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN 
style="COLOR: #000000"><BR>&nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN 
style="COLOR: #0000ff">&lt;</SPAN><SPAN 

⌨️ 快捷键说明

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