关于<html:errors>和<html:messages>的几点使用心得和经验 在Struts项目中,标签的功能非常强大。以前没有用过,这次初次使用,因此在编码的过程中,可谓一波三折。虽然网上的资料非常丰富,但是"网上的来终觉浅,绝知此事要躬行”,因此在使用的过程中频频出现别人没有提及到的问题。使用<html:errors>和<html:messages>这两个标签时,按照以下步骤写代码,就遇到问题:
1.我在Actionform中的Validate()方法中,定义了ActionErrors errors对象,在ActionForm中的消息类型集合目前只能采用它来封装。里面封装的消息信息为ActionMessages.GLOBAL_MESSAGE, new ActionMessage("key");
2.我在Action中用的是ActionMessages messages类来封装错误和提示信息,里面封装的消息信息为ActionMessages.GLOBAL_MESSAGE, new ActionMessage("key");其中保存方法为addMessages(request,messages);
3.我在页面上采用一个<div>来显示所有的系统消息(包括ActionForm中的消息和Action中的消息),我想做到底效果是,当系统没有消息时,<div>不显示;而当系统有消息时(包括ActionForm中的消息和Action中的消息),我就用<div>来显示系统消息。
具体的代码如:
<logic:messagesPresent> //--有消息才显示
<div><html:errors /></div>
</logic:messagesPresent>
此时运行程序就遇到了一个问题:
只当ActionForm中有消息时,能在页面上显示,但是Action中的消息不能显示。
后来,我把Action程序中的保存消息的方法改成saveErrors(request,messages);此时在页面上能显示Action中的消息,但是,ActionForm中有消息时页面就不能显示了。 遇到这个问题,我到处查阅资料,搞了一上午,最后终于实现了当初我们的设计:
action中消息保存方法为addMessages(request,messages); 具体做法如下:<logic:messagesPresent>
<div align="left" id="menu_error" onClick="hideMenu('menu_error');">
<font color=blue class="style5">
系统提示! <br> <br> </font> <font>
<html:messages id="message" message="false">
<bean:write name="message" /><br>
</html:messages> </font> <br> <br> </div>
</logic:messagesPresent> <logic:messagesPresent message="true"> <div align="left" id="menu_error" onClick="hideMenu('menu_error');"> <font color=blue class="style5"> 系统提示! <br> <br> </font> <font> <html:messages name="GLOBAL_MESSAGE" id="message" message="true"> <bean:write name="message" /><br> </html:messages> </font> <br> <br> </div> </logic:messagesPresent>
解释:<logic:messagesPresent>是表示在系统作用域范围内,如果存在ActionMessage对象就执行用户想要的操作。(一般需求就是显示消息) <logic:messagesPresent>的message属性可以标记消息的类型,值为true或false,false对应GLOBAL_ERROR,true对应GLOBAL_MESSAGE。GLOBAL_ERROR就是错误消息(即ActionErrors类型),GLOBAL_MESSAGE是提示消息(即ActionMessages类型),默认值为false; 因此,我想要显示错误消息就用<logic:messagesPresent>或<logic:messagesPresent message="false">; 显示消息的语句可以用<html:errors> 或者 <html:messages id="message" message="false"> <bean:write name="message" /><br> </html:messages> ---------------------- 显示提示消息就用<logic:messagesPresent message="true">; <html:messages id="message" message="true"> <bean:write name="message" /><br> </html:messages> -------------------- 上面就是<html:errors>和<html:messages>的具体使用方法和技巧。
分享到:
相关推荐
bean:struts 9 bean:write 9 html:base 10 html:cancel 11 html:select 12 html:checkbox 14 html:radio 15 html:multibox 15 html:link 16 html:errors 18 html:javascript 20 html:xhtml 21 logic:iterate 21 ...
<%@ taglib prefix="s" uri="/struts-tags" %> 就能使用struts2.0的标签库 下面就介绍每个标签的具体应用实例说明:按字母排列 A: 1. 2. <s:a href=""></s:a>-----超链接,类似于html里的<a></a> 3. <s:...
当执行validate方法时,返回的ActionErrors检查内部是否存在元素,有则返回到原来的input指定的页面;否则继续前进,执行Action的execute方法!
struts提供了<html:errors/>标签来显示整个ActionErrors的错误信息。但要在struts-config.xml中设置<action ...
errors code
13.1 使用Struts Bean标签保存与传输数据小实例 15 第14章 Struts Logic标签库 15 14.1 如何使用Logic标签进行基于值的条件显示 15 14.1 如何使用Logic标签进行字符串匹配 15 14.1 如何使用Logic标签来检测值是否...
13.9. 使用Spring的表单标签库 1 13.9.1. 配置 1 13.9.2. form标签 1 13.9.3. input标签 3 13.9.4. checkbox标签 3 13.9.5. checkboxes标签 6 13.9.6. radiobutton标签 6 13.9.7. radiobuttons标签 7 13.9.8. ...
Key was created with errors: Warning: JKS 密钥库使用专用格式。建议使用 “keytool -importkeystore -srckeystore E:\lvchuang\lvchuang.jks -destkeystore E:\lvchuang\lvchuang.jks -deststoretype pkcs12” ...
cfg_errors.gocfg_errors.gocfg_errors.gocfg_errors.gocfg_errors.gocfg_errors.gocfg_errors.gocfg_errors.gocfg_errors.gocfg_errors.go
graphql错误 :warning: 不推荐使用该gem,而建议使用graphql gem中的新GraphQL::Execution::Errors 。 查看更多详细信息 。 这个gem为提供了简单的错误处理。强调每个字段的错误处理。 与Rails类似, rescue_from块...
# all warnings being treated as errors ## 技巧 在ubuntu系统下编译一个程序包,有时会遇到这样的错误: $ make ... cc1: all warnings being treated as errors
java-struts2.2的驱动包 2009-8-29 14:02:04 org.apache.catalina.core.AprLifecycleListener init 信息: The APR based Apache Tomcat Native library which allows optimal performance in production ...
<br/> 核心:Struts的核心是ActionSevlet,ActionSevlet的核心是Struts-config.xml。这在后面还会详细讨论。 <br/>6、Struts安装 Struts的安装比较简单,下面的以Tomcat 4.0.4为例,讲述安装过程。...
learning representations by back-propagating errors
检测语法错误,Detection of grammatical errors involving prepositions
标准库errors包和。 这是一个轻量级的库,它合并了标准库errors包和。 它还会向后移植一些功能(例如与Go 1.13错误处理相关的功能)。 标准库功能: New会产生堆栈跟踪错误 Unwrap支持Go 1.13包装器( interface...
一个图形化的MatLab框架,用于在变量误差环境中估算静态,动态线性和多项式系统的参数,对其进行建模和仿真,目的是比较各种估算策略。
使用完成 : $ npm install http-errors例子var createError = require ( 'http-errors' )var express = require ( 'express' )var app = express ( )app . use ( function ( req , res , next ) { if ( ! req . ...
英文单词拼写混淆集:spell-errors.txt
The usual implementation of malloc and free are unforgiving to errors in their callers' code, including cases where the programmer overflows an array, forgets to free memory, or frees a memory block ...