﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Cool eye-随笔分类-Struts</title><link>http://www.blogjava.net/joeyeezhang/category/6956.html</link><description /><language>zh-cn</language><lastBuildDate>Fri, 02 Mar 2007 06:50:32 GMT</lastBuildDate><pubDate>Fri, 02 Mar 2007 06:50:32 GMT</pubDate><ttl>60</ttl><item><title>message in struts</title><link>http://www.blogjava.net/joeyeezhang/archive/2006/02/13/30423.html</link><dc:creator>joeyeezhang</dc:creator><author>joeyeezhang</author><pubDate>Mon, 13 Feb 2006 03:04:00 GMT</pubDate><guid>http://www.blogjava.net/joeyeezhang/archive/2006/02/13/30423.html</guid><wfw:comment>http://www.blogjava.net/joeyeezhang/comments/30423.html</wfw:comment><comments>http://www.blogjava.net/joeyeezhang/archive/2006/02/13/30423.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/joeyeezhang/comments/commentRss/30423.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/joeyeezhang/services/trackbacks/30423.html</trackback:ping><description><![CDATA[<BR>1.错误和信息的处理. <BR><BR>首先在资源文件中定义错误信息和普通信息.如:MessageResources.properties中定义如下: <BR>
<TABLE cellSpacing=1 cellPadding=3 width="90%" align=center border=0>
<TBODY>
<TR>
<TD><SPAN class=genmed><B>java代码:&nbsp;</B></SPAN></TD></TR>
<TR>
<TD class=code>
<DIV style="FONT-FAMILY: 'Courier New', Courier, monospace"><BR><BR># <BR># Resources <SPAN style="FONT-WEIGHT: bold; COLOR: #990066" ?>for</SPAN> testing &lt;html:errors&gt; tag. <BR># <BR><BR>errors.<SPAN style="COLOR: #000000">header</SPAN>=&lt;table&gt; <BR>errors.<SPAN style="COLOR: #000000">footer</SPAN>=&lt;/table&gt; <BR>errors.<SPAN style="COLOR: #000000">prefix</SPAN>=&lt;tr&gt;&lt;td&gt; <BR>errors.<SPAN style="COLOR: #000000">suffix</SPAN>=&lt;/td&gt;&lt;/tr&gt; <BR><BR>property1error1=Property <SPAN style="COLOR: #000000" ?>1</SPAN>, <SPAN style="COLOR: #aaaadd" ?>Error</SPAN> <SPAN style="COLOR: #000000" ?>1</SPAN> <BR>property2error1=Property <SPAN style="COLOR: #000000" ?>2</SPAN>, <SPAN style="COLOR: #aaaadd" ?>Error</SPAN> <SPAN style="COLOR: #000000" ?>1</SPAN> <BR>property2error2=Property <SPAN style="COLOR: #000000" ?>2</SPAN>, <SPAN style="COLOR: #aaaadd" ?>Error</SPAN> <SPAN style="COLOR: #000000" ?>2</SPAN> <BR>property2error3=Property <SPAN style="COLOR: #000000" ?>2</SPAN>, <SPAN style="COLOR: #aaaadd" ?>Error</SPAN> <SPAN style="COLOR: #000000" ?>3</SPAN> <BR>property3error1=Property <SPAN style="COLOR: #000000" ?>3</SPAN>, <SPAN style="COLOR: #aaaadd" ?>Error</SPAN> <SPAN style="COLOR: #000000" ?>1</SPAN> <BR>property3error2=Property <SPAN style="COLOR: #000000" ?>3</SPAN>, <SPAN style="COLOR: #aaaadd" ?>Error</SPAN> <SPAN style="COLOR: #000000" ?>2</SPAN> <BR>globalError=Global <SPAN style="COLOR: #aaaadd" ?>Error</SPAN> <BR><BR># <BR># Resources <SPAN style="FONT-WEIGHT: bold; COLOR: #990066" ?>for</SPAN> testing &lt;html:messages&gt; tag. <BR># <BR><BR>messages.<SPAN style="COLOR: #000000">header</SPAN>=&lt;table&gt; <BR>messages.<SPAN style="COLOR: #000000">footer</SPAN>=&lt;/table&gt; <BR><BR>property1message1=Property <SPAN style="COLOR: #000000" ?>1</SPAN>, Message <SPAN style="COLOR: #000000" ?>1</SPAN> <BR>property2message1=Property <SPAN style="COLOR: #000000" ?>2</SPAN>, Message <SPAN style="COLOR: #000000" ?>1</SPAN> <BR>property2message2=Property <SPAN style="COLOR: #000000" ?>2</SPAN>, Message <SPAN style="COLOR: #000000" ?>2</SPAN> <BR>property2message3=Property <SPAN style="COLOR: #000000" ?>2</SPAN>, Message <SPAN style="COLOR: #000000" ?>3</SPAN> <BR>property3message1=Property <SPAN style="COLOR: #000000" ?>3</SPAN>, Message <SPAN style="COLOR: #000000" ?>1</SPAN> <BR>property3message2=Property <SPAN style="COLOR: #000000" ?>3</SPAN>, Message <SPAN style="COLOR: #000000" ?>2</SPAN> <BR>globalMessage=Global Message <BR></DIV><BR></TD></TR></TBODY></TABLE><SPAN class=postbody><BR><BR>在程序中定义错误和信息类,这个例子写在JSP中 <BR><BR></SPAN>
<TABLE cellSpacing=1 cellPadding=3 width="90%" align=center border=0>
<TBODY>
<TR>
<TD><SPAN class=genmed><B>java代码:&nbsp;</B></SPAN></TD></TR>
<TR>
<TD class=code>
<DIV style="FONT-FAMILY: 'Courier New', Courier, monospace"><BR><BR>&lt;% <BR>&nbsp; &nbsp; &nbsp; ActionErrors errors = <SPAN style="FONT-WEIGHT: bold; COLOR: #990066" ?>new</SPAN> ActionErrors<SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #000000">)</SPAN>; <BR>&nbsp; &nbsp; &nbsp; errors.<SPAN style="COLOR: #000000">add</SPAN><SPAN style="COLOR: #000000">(</SPAN>"property1", <SPAN style="FONT-WEIGHT: bold; COLOR: #990066" ?>new</SPAN> ActionError<SPAN style="COLOR: #000000">(</SPAN>"property1error1"<SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">)</SPAN>; <BR>&nbsp; &nbsp; &nbsp; errors.<SPAN style="COLOR: #000000">add</SPAN><SPAN style="COLOR: #000000">(</SPAN>"property2", <SPAN style="FONT-WEIGHT: bold; COLOR: #990066" ?>new</SPAN> ActionError<SPAN style="COLOR: #000000">(</SPAN>"property2error1"<SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">)</SPAN>; <BR>&nbsp; &nbsp; &nbsp; errors.<SPAN style="COLOR: #000000">add</SPAN><SPAN style="COLOR: #000000">(</SPAN>"property2", <SPAN style="FONT-WEIGHT: bold; COLOR: #990066" ?>new</SPAN> ActionError<SPAN style="COLOR: #000000">(</SPAN>"property2error2"<SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">)</SPAN>; <BR>&nbsp; &nbsp; &nbsp; errors.<SPAN style="COLOR: #000000">add</SPAN><SPAN style="COLOR: #000000">(</SPAN>"property2", <SPAN style="FONT-WEIGHT: bold; COLOR: #990066" ?>new</SPAN> ActionError<SPAN style="COLOR: #000000">(</SPAN>"property2error3"<SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">)</SPAN>; <BR>&nbsp; &nbsp; &nbsp; errors.<SPAN style="COLOR: #000000">add</SPAN><SPAN style="COLOR: #000000">(</SPAN>"property3", <SPAN style="FONT-WEIGHT: bold; COLOR: #990066" ?>new</SPAN> ActionError<SPAN style="COLOR: #000000">(</SPAN>"property3error1"<SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">)</SPAN>; <BR>&nbsp; &nbsp; &nbsp; errors.<SPAN style="COLOR: #000000">add</SPAN><SPAN style="COLOR: #000000">(</SPAN>"property3", <SPAN style="FONT-WEIGHT: bold; COLOR: #990066" ?>new</SPAN> ActionError<SPAN style="COLOR: #000000">(</SPAN>"property3error2"<SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">)</SPAN>; <BR>&nbsp; &nbsp; &nbsp; errors.<SPAN style="COLOR: #000000">add</SPAN><SPAN style="COLOR: #000000">(</SPAN>ActionErrors.<SPAN style="COLOR: #000000">GLOBAL_ERROR</SPAN>, <SPAN style="FONT-WEIGHT: bold; COLOR: #990066" ?>new</SPAN> ActionError<SPAN style="COLOR: #000000">(</SPAN>"globalError"<SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">)</SPAN>; <BR>&nbsp; &nbsp; &nbsp; request.<SPAN style="COLOR: #000000">setAttribute</SPAN><SPAN style="COLOR: #000000">(</SPAN>Globals.<SPAN style="COLOR: #000000">ERROR_KEY</SPAN>, errors<SPAN style="COLOR: #000000">)</SPAN>; <BR><BR>&nbsp; &nbsp; &nbsp; ActionMessages messages = <SPAN style="FONT-WEIGHT: bold; COLOR: #990066" ?>new</SPAN> ActionMessages<SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #000000">)</SPAN>; <BR>&nbsp; &nbsp; &nbsp; messages.<SPAN style="COLOR: #000000">add</SPAN><SPAN style="COLOR: #000000">(</SPAN>"property1", <SPAN style="FONT-WEIGHT: bold; COLOR: #990066" ?>new</SPAN> ActionMessage<SPAN style="COLOR: #000000">(</SPAN>"property1message1"<SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">)</SPAN>; <BR>&nbsp; &nbsp; &nbsp; messages.<SPAN style="COLOR: #000000">add</SPAN><SPAN style="COLOR: #000000">(</SPAN>"property2", <SPAN style="FONT-WEIGHT: bold; COLOR: #990066" ?>new</SPAN> ActionMessage<SPAN style="COLOR: #000000">(</SPAN>"property2message1"<SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">)</SPAN>; <BR>&nbsp; &nbsp; &nbsp; messages.<SPAN style="COLOR: #000000">add</SPAN><SPAN style="COLOR: #000000">(</SPAN>"property2", <SPAN style="FONT-WEIGHT: bold; COLOR: #990066" ?>new</SPAN> ActionMessage<SPAN style="COLOR: #000000">(</SPAN>"property2message2"<SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">)</SPAN>; <BR>&nbsp; &nbsp; &nbsp; messages.<SPAN style="COLOR: #000000">add</SPAN><SPAN style="COLOR: #000000">(</SPAN>"property2", <SPAN style="FONT-WEIGHT: bold; COLOR: #990066" ?>new</SPAN> ActionMessage<SPAN style="COLOR: #000000">(</SPAN>"property2message3"<SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">)</SPAN>; <BR>&nbsp; &nbsp; &nbsp; messages.<SPAN style="COLOR: #000000">add</SPAN><SPAN style="COLOR: #000000">(</SPAN>"property3", <SPAN style="FONT-WEIGHT: bold; COLOR: #990066" ?>new</SPAN> ActionMessage<SPAN style="COLOR: #000000">(</SPAN>"property3message1"<SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">)</SPAN>; <BR>&nbsp; &nbsp; &nbsp; messages.<SPAN style="COLOR: #000000">add</SPAN><SPAN style="COLOR: #000000">(</SPAN>"property3", <SPAN style="FONT-WEIGHT: bold; COLOR: #990066" ?>new</SPAN> ActionMessage<SPAN style="COLOR: #000000">(</SPAN>"property3message2"<SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">)</SPAN>; <BR>&nbsp; &nbsp; &nbsp; messages.<SPAN style="COLOR: #000000">add</SPAN><SPAN style="COLOR: #000000">(</SPAN>ActionMessages.<SPAN style="COLOR: #000000">GLOBAL_MESSAGE</SPAN>, <SPAN style="FONT-WEIGHT: bold; COLOR: #990066" ?>new</SPAN> ActionMessage<SPAN style="COLOR: #000000">(</SPAN>"globalMessage"<SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">)</SPAN>; <BR>&nbsp; &nbsp; &nbsp; request.<SPAN style="COLOR: #000000">setAttribute</SPAN><SPAN style="COLOR: #000000">(</SPAN>Globals.<SPAN style="COLOR: #000000">MESSAGE_KEY</SPAN>, messages<SPAN style="COLOR: #000000">)</SPAN>; <BR>&nbsp; &nbsp; %&gt; <BR></DIV><BR></TD></TR></TBODY></TABLE><SPAN class=postbody><BR><BR><BR><BR>显示错误: <BR></SPAN>
<TABLE cellSpacing=1 cellPadding=3 width="90%" align=center border=0>
<TBODY>
<TR>
<TD><SPAN class=genmed><B>java代码:&nbsp;</B></SPAN></TD></TR>
<TR>
<TD class=code>
<DIV style="FONT-FAMILY: 'Courier New', Courier, monospace"><BR><BR>&lt;html:errors property="property1" /&gt; <BR>&lt;html:errors property="property2" /&gt; <BR></DIV><BR></TD></TR></TBODY></TABLE><SPAN class=postbody><BR>显示信息: <BR></SPAN>
<TABLE cellSpacing=1 cellPadding=3 width="90%" align=center border=0>
<TBODY>
<TR>
<TD><SPAN class=genmed><B>java代码:&nbsp;</B></SPAN></TD></TR>
<TR>
<TD class=code>
<DIV style="FONT-FAMILY: 'Courier New', Courier, monospace"><BR><BR>&lt;html:messages property="property1" message="<SPAN style="FONT-WEIGHT: bold; COLOR: #990066" ?>true</SPAN>" id="msg" header="messages.<SPAN style="COLOR: #000000">header</SPAN>" footer="messages.<SPAN style="COLOR: #000000">footer</SPAN>"&gt; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tr&gt; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;%= pageContext.<SPAN style="COLOR: #000000">getAttribute</SPAN><SPAN style="COLOR: #000000">(</SPAN>"msg"<SPAN style="COLOR: #000000">)</SPAN> %&gt; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/td&gt; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/tr&gt; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/html:messages&gt; <BR><BR>&lt;html:messages message="<SPAN style="FONT-WEIGHT: bold; COLOR: #990066" ?>true</SPAN>" id="msg" header="messages.<SPAN style="COLOR: #000000">header</SPAN>" footer="messages.<SPAN style="COLOR: #000000">footer</SPAN>"&gt; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tr&gt; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;%= pageContext.<SPAN style="COLOR: #000000">getAttribute</SPAN><SPAN style="COLOR: #000000">(</SPAN>"msg"<SPAN style="COLOR: #000000">)</SPAN> %&gt; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/td&gt; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/tr&gt; <BR>&lt;/html:messages&gt; <BR></DIV><BR></TD></TR></TBODY></TABLE><img src ="http://www.blogjava.net/joeyeezhang/aggbug/30423.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/joeyeezhang/" target="_blank">joeyeezhang</a> 2006-02-13 11:04 <a href="http://www.blogjava.net/joeyeezhang/archive/2006/02/13/30423.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>About Tag state in struts</title><link>http://www.blogjava.net/joeyeezhang/archive/2006/01/12/27789.html</link><dc:creator>joeyeezhang</dc:creator><author>joeyeezhang</author><pubDate>Thu, 12 Jan 2006 08:56:00 GMT</pubDate><guid>http://www.blogjava.net/joeyeezhang/archive/2006/01/12/27789.html</guid><wfw:comment>http://www.blogjava.net/joeyeezhang/comments/27789.html</wfw:comment><comments>http://www.blogjava.net/joeyeezhang/archive/2006/01/12/27789.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/joeyeezhang/comments/commentRss/27789.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/joeyeezhang/services/trackbacks/27789.html</trackback:ping><description><![CDATA[<P>In struts, there is only one tag instance with one tag, so if there is one state field in tag class, please don't forget to revert the value of the state field before returning .<BR>For example:<BR>public class UserDefinedTableTag&nbsp;&nbsp; extends TagSupport<BR>{<BR>&nbsp;&nbsp;&nbsp;private boolean isAddRichScript = false;<BR>&nbsp;&nbsp;&nbsp;public int doEndTag() throws JspException {<BR><BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;isAddRichScript = false;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return EVAL_PAGE;</P>
<P>&nbsp;&nbsp;&nbsp; }<BR>private void addNote(UserDefinedTableColumnConfig userDefinedTableColumnConfig, StringBuffer outStr) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if("T".equals(userDefinedTableColumnConfig.getRichHtml()))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(!isAddRichScript)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; isAddRichScript = true;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outStr.append(richScript);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outStr.append(richHtml);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>}</P><img src ="http://www.blogjava.net/joeyeezhang/aggbug/27789.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/joeyeezhang/" target="_blank">joeyeezhang</a> 2006-01-12 16:56 <a href="http://www.blogjava.net/joeyeezhang/archive/2006/01/12/27789.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>