`

message in struts

阅读更多

1.错误和信息的处理.

首先在资源文件中定义错误信息和普通信息.如:MessageResources.properties中定义如下:
java代码: 


#
# Resources for testing <html:errors> tag.
#

errors.header=<table>
errors.footer=</table>
errors.prefix=<tr><td>
errors.suffix=</td></tr>

property1error1=Property 1, Error 1
property2error1=Property 2, Error 1
property2error2=Property 2, Error 2
property2error3=Property 2, Error 3
property3error1=Property 3, Error 1
property3error2=Property 3, Error 2
globalError=Global Error

#
# Resources for testing <html:messages> tag.
#

messages.header=<table>
messages.footer=</table>

property1message1=Property 1, Message 1
property2message1=Property 2, Message 1
property2message2=Property 2, Message 2
property2message3=Property 2, Message 3
property3message1=Property 3, Message 1
property3message2=Property 3, Message 2
globalMessage=Global Message



在程序中定义错误和信息类,这个例子写在JSP中

java代码: 


<%
      ActionErrors errors = new ActionErrors();
      errors.add("property1", new ActionError("property1error1"));
      errors.add("property2", new ActionError("property2error1"));
      errors.add("property2", new ActionError("property2error2"));
      errors.add("property2", new ActionError("property2error3"));
      errors.add("property3", new ActionError("property3error1"));
      errors.add("property3", new ActionError("property3error2"));
      errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("globalError"));
      request.setAttribute(Globals.ERROR_KEY, errors);

      ActionMessages messages = new ActionMessages();
      messages.add("property1", new ActionMessage("property1message1"));
      messages.add("property2", new ActionMessage("property2message1"));
      messages.add("property2", new ActionMessage("property2message2"));
      messages.add("property2", new ActionMessage("property2message3"));
      messages.add("property3", new ActionMessage("property3message1"));
      messages.add("property3", new ActionMessage("property3message2"));
      messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("globalMessage"));
      request.setAttribute(Globals.MESSAGE_KEY, messages);
    %>





显示错误:
java代码: 


<html:errors property="property1" />
<html:errors property="property2" />


显示信息:
java代码: 


<html:messages property="property1" message="true" id="msg" header="messages.header" footer="messages.footer">
            <tr>
              <td>
                     <%= pageContext.getAttribute("msg") %>
              </td>
            </tr>
          </html:messages>

<html:messages message="true" id="msg" header="messages.header" footer="messages.footer">
            <tr>
              <td>
               <%= pageContext.getAttribute("msg") %>
              </td>
            </tr>
</html:messages>

分享到:
评论

相关推荐

    struts配置元素详解

    ”1.0” encoding=”ISO-8859-1”?&gt; &lt;!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" ... &lt;message-resources / &gt; &lt;plug-in /&gt; &lt;/struts-config&gt;

    Struts2 国际化字符串 拦截器

    文件的国际化字符串中使用OGNL,格式为${表达式},例如: validation.required=${getText(fileName)} is required 2. 使用java.text.... &lt;h2&gt;Message rendered in Velocity: $message struts-dojo-tags

    Myeclipse开发struts+hibernate+spring新手入门--环境配置---项目开发示例

    同加载struts方式类似,选择Myeclipse后在弹出的二级菜单中选择Add spring in action in action Capabilities…后提示如下图所示: 选择所需要的spring in action in action包,然后默认下一步,直到完成。 到此...

    Struts in Action中文版

    2.6.2. Struts的强项........................................................................................................58 Struts in Action 中文版 Lastest Revised:10/14/2005 10:27:00 AM ...

    Struts 2 Form Tags

    In our previous tutorials that explained how to use Struts 2 forms (Processing Forms, Form Validation, and Message Resource Files) we covered how to use the Struts 2 head, form, textfield controls ...

    struts in Action

    1.1.1. 谁创建了Struts?...................................................................................................19 1.1.2. 为什么Struts 要开源?....................................................

    struts_2.3.12GA_API文档(chm版本)

    Gets a message based on a key using the supplied args, as defined in MessageFormat, or null if no message is found. String getText(String aTextName, String defaultValue) Gets a message based on a...

    外文翻译 stus MVC

    Struts can help you control change in your Web project and promote specialization. Even if you never implement a system with Struts, you may get some ideas for your future servlets and JSP page ...

    Java+structs快速学习指南

    messagesNotPresent Generate the nested body content of this tag if the specified message is not present in this request. messagesPresent Generate the nested body content of this tag if the specified ...

    freemarker总结

    &lt;#assign mail="jsmith@other.com" in my&gt; ${my.mail} l 输出结果: jsmith@acme.com jsmith@other.com l 数据模型中的变量任何地方都可见,也包括不同的名字空间,下面是修改的库: &lt;p&gt;Copyright ...

    超级有影响力霸气的Java面试题大全文档

    EJB包括Session Bean、Entity Bean、Message Driven Bean,基于JNDI、RMI、JAT等技术实现。 SessionBean在J2EE应用程序中被用来完成一些服务器端的业务操作,例如访问数据库、调用其他EJB组件。EntityBean被用来...

    jsp探针 ver0.1

    Class.forName("org.apache.struts.action.ActionServlet"); supportStruts = true; } catch (ClassNotFoundException ex) { } try { Class.forName("javax.naming.Name"); supportJNDI = true; } catch ...

    Spring中文帮助文档

    15.4. Struts 15.4.1. ContextLoaderPlugin 15.4.2. ActionSupport Classes 15.5. Tapestry 15.5.1. 注入 Spring 托管的 beans 15.6. WebWork 15.7. 更多资源 16. Portlet MVC框架 16.1. 介绍 16.1.1. 控制...

    Spring API

    15.4. Struts 15.4.1. ContextLoaderPlugin 15.4.2. ActionSupport Classes 15.5. Tapestry 15.5.1. 注入 Spring 托管的 beans 15.6. WebWork 15.7. 更多资源 16. Portlet MVC框架 16.1. 介绍 16.1.1. 控制...

    java 面试题 总结

    EJB包括Session Bean、Entity Bean、Message Driven Bean,基于JNDI、RMI、JAT等技术实现。 SessionBean在J2EE应用程序中被用来完成一些服务器端的业务操作,例如访问数据库、调用其他EJB组件。EntityBean被用来...

    spring chm文档

    15.4. Struts 15.4.1. ContextLoaderPlugin 15.4.2. ActionSupport 类 15.5. Tapestry 15.5.1. 注入 Spring 托管的 beans 15.6. WebWork 15.7. 更多资源 16. Portlet MVC框架 16.1. 介绍 16.1.1. 控制器 - ...

    JAVA上百实例源码以及开源项目

     Message-Driven Bean EJB实例源代码,演示一个接收购物订单的消息驱动Bean,处理这个订单同时通过e-mail的形式  //给客户发一个感谢消息,消息驱动Bean必须实现两个接口MessageDrivenBean和MessageListener  在...

    JAVA上百实例源码以及开源项目源代码

     Message-Driven Bean EJB实例源代码,演示一个接收购物订单的消息驱动Bean,处理这个订单同时通过e-mail的形式  //给客户发一个感谢消息,消息驱动Bean必须实现两个接口MessageDrivenBean和MessageListener  在...

    Spring-Reference_zh_CN(Spring中文参考手册)

    15.4. Struts 15.4.1. ContextLoaderPlugin 15.4.1.1. DelegatingRequestProcessor 15.4.1.2. DelegatingActionProxy 15.4.2. ActionSupport 类 15.5. Tapestry 15.5.1. 注入 Spring 托管的 beans 15.5.1.1. 将 ...

Global site tag (gtag.js) - Google Analytics