﻿<?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-Alec's BLOG-文章分类-Struts技术</title><link>http://www.blogjava.net/lyq32/category/29727.html</link><description>Java will win the world</description><language>zh-cn</language><lastBuildDate>Thu, 28 Feb 2008 01:49:33 GMT</lastBuildDate><pubDate>Thu, 28 Feb 2008 01:49:33 GMT</pubDate><ttl>60</ttl><item><title>html:errors和html:messages</title><link>http://www.blogjava.net/lyq32/articles/182388.html</link><dc:creator>Alec</dc:creator><author>Alec</author><pubDate>Wed, 27 Feb 2008 01:54:00 GMT</pubDate><guid>http://www.blogjava.net/lyq32/articles/182388.html</guid><wfw:comment>http://www.blogjava.net/lyq32/comments/182388.html</wfw:comment><comments>http://www.blogjava.net/lyq32/articles/182388.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lyq32/comments/commentRss/182388.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lyq32/services/trackbacks/182388.html</trackback:ping><description><![CDATA[<p style="margin: 0cm 0cm 0pt"><span style="font-size: 8pt"><font face="宋体"><font size="2"><font color="#ff0000">&lt;html:messages&gt;</font><br />
</font></font><font face="宋体" size="2">Action 中 :<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ActionMessages message = new ActionMessages();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; message.add(" 消息句柄 ",new ActionMessage(" 资源文件中 Key 值 ",String 类型描述信息 ));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.addMessages(request,message);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ActionForward;<br />
JSP 页面中 :<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;html:messages id=" 指定使用消息的标识 " property=" 消息句柄 " message="true|false"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;bean:write name=" 以上所指 ID 标识 "/&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/html:messages&gt; </font></span></p>
<p style="margin: 0cm 0cm 0pt"><span style="font-size: 8pt"><font face="宋体" size="2">例如：</font></span></p>
<p style="margin: 0cm 0cm 0pt"><span style="font-size: 8pt"><font face="宋体" size="2">Action方法中:<br />
saveMessage(request,"页面要显示的消息");</font></span></p>
<p style="margin: 0cm 0cm 0pt"><span style="font-size: 8pt"><span style="font-size: 8pt"><font face="宋体" size="2">Action的调用的方法，可以写真<span style="font-size: 8pt"><span style="font-size: 8pt"><font size="2">Action实现类的父类 BaseDispatchAction </font>中</span></span>:</font></span></span></p>
<span style="font-size: 8pt">
<p style="margin: 0cm 0cm 0pt"><span style="font-size: 8pt"><font face="宋体" size="2">public ActionMessages saveMessage(HttpServletRequest request, String key) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ActionMessages messages = new ActionMessages();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return saveMessage(messages, request, key);<br />
}</font></span></p>
<p style="margin: 0cm 0cm 0pt"><span style="font-size: 8pt"><font face="宋体" size="2">protected ActionMessages saveMessage(ActionMessages messages,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HttpServletRequest request, String key) {</font></span></p>
<p style="margin: 0cm 0cm 0pt"><span style="font-size: 8pt"><font face="宋体" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(key));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; saveMessages(request, messages);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return messages;<br />
}</font></span></p>
<p style="margin: 0cm 0cm 0pt"><span style="font-size: 8pt"><font face="宋体" size="2">页面：</font></span></p>
<p style="margin: 0cm 0cm 0pt"><span style="font-size: 8pt"><font face="宋体" size="2">&lt;html:messages id="msg" message="true"&gt;&lt;bean:write name="msg"/&gt;&lt;/html:messages&gt;</font></span></p>
</span>
<p style="margin: 0cm 0cm 0pt"><span style="font-size: 8pt"><font face="宋体"><font size="2"><font color="#ff0000">&lt;html:errors&gt;</font><br />
</font></font><font face="宋体" size="2">Action 中 :<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ActionMessages message = new ActionMessages();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; message.add(" 消息句柄 ",new ActionMessage(" 资源文件中 Key 值 ",String 类型描述信息 ));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.saveErrors(request,message);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ActionForward;<br />
JSP 页面中 :<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;html:errors property=" 消息句柄 "/&gt; </font></span></p>
<p style="margin: 0cm 0cm 0pt"><span style="font-size: 8pt"><font face="宋体" size="2">如果Action中这样设定(false)，页面的提示信息将不从资源文件里读取:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ActionMessages message = new ActionMessages();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; message.add("消息句柄",new ActionMessage("String类型描述信息));",false));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.saveErrors(request,message);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ActionForward;<br />
JSP页面:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;html:errors/&gt;或&lt;html:errors property="消息句柄"/&gt;</font></span></p>
<img src ="http://www.blogjava.net/lyq32/aggbug/182388.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lyq32/" target="_blank">Alec</a> 2008-02-27 09:54 <a href="http://www.blogjava.net/lyq32/articles/182388.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>