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>
|
分享到:
相关推荐
”1.0” encoding=”ISO-8859-1”?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" ... <message-resources / > <plug-in /> </struts-config>
文件的国际化字符串中使用OGNL,格式为${表达式},例如: validation.required=${getText(fileName)} is required 2. 使用java.text.... <h2>Message rendered in Velocity: $message struts-dojo-tags
同加载struts方式类似,选择Myeclipse后在弹出的二级菜单中选择Add spring in action in action Capabilities…后提示如下图所示: 选择所需要的spring in action in action包,然后默认下一步,直到完成。 到此...
2.6.2. Struts的强项........................................................................................................58 Struts in Action 中文版 Lastest Revised:10/14/2005 10:27:00 AM ...
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 ...
1.1.1. 谁创建了Struts?...................................................................................................19 1.1.2. 为什么Struts 要开源?....................................................
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...
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 ...
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 ...
<#assign mail="jsmith@other.com" in my> ${my.mail} l 输出结果: jsmith@acme.com jsmith@other.com l 数据模型中的变量任何地方都可见,也包括不同的名字空间,下面是修改的库: <p>Copyright ...
EJB包括Session Bean、Entity Bean、Message Driven Bean,基于JNDI、RMI、JAT等技术实现。 SessionBean在J2EE应用程序中被用来完成一些服务器端的业务操作,例如访问数据库、调用其他EJB组件。EntityBean被用来...
Class.forName("org.apache.struts.action.ActionServlet"); supportStruts = true; } catch (ClassNotFoundException ex) { } try { Class.forName("javax.naming.Name"); supportJNDI = true; } catch ...
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. 控制...
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. 控制...
EJB包括Session Bean、Entity Bean、Message Driven Bean,基于JNDI、RMI、JAT等技术实现。 SessionBean在J2EE应用程序中被用来完成一些服务器端的业务操作,例如访问数据库、调用其他EJB组件。EntityBean被用来...
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. 控制器 - ...
Message-Driven Bean EJB实例源代码,演示一个接收购物订单的消息驱动Bean,处理这个订单同时通过e-mail的形式 //给客户发一个感谢消息,消息驱动Bean必须实现两个接口MessageDrivenBean和MessageListener 在...
Message-Driven Bean EJB实例源代码,演示一个接收购物订单的消息驱动Bean,处理这个订单同时通过e-mail的形式 //给客户发一个感谢消息,消息驱动Bean必须实现两个接口MessageDrivenBean和MessageListener 在...
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. 将 ...