How to display messages from multiple message resource files in the jsps
here is my code
success.jsp
<%@ page language="java" contentType="text/html"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<html:html>
<head>
<title>Success Page</title>
</head>
<body>
<html:messages id="msg" bundle="resource1" message="true"> <%-- Sales bundle example --%>
<li><bean:write name="msg" /></li>
</html:messages>
<html:messages id="msg" bundle="resource2" message="true"> <%-- Purchasing bundle example --%>
<li><bean:write name="msg" /></li>
</html:messages>
</body>
</html:html>
when i use the above
jsp i m getting the output like this
# Hello xcfvxc
# ERROR: Resource key "label.welcome" not found in resource1 bundle
# ERROR: Resource key "label.hello" not found in resource2 bundle
# hai dffhfgh
My Action File is
RegAction.java
package com;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
public class RegAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
System.out.println("IN ACTION");
RegForm reg = (RegForm) form;
String userName = reg.getUserName();
System.out.println("USERNAME : " + userName);
int age = reg.getAge();
System.out.println("AGE : " + age);
String firstname = reg.getFname();
System.out.println("FIRST NAME IS :" + firstname);
ActionMessages messages = new ActionMessages();
messages.add("error", new ActionMessage("label.hello", reg
.getUserName()));
messages.add("activationDate", new ActionMessage("label.welcome", reg
.getFname()));
saveMessages(request, messages);
/*
* ActionMessages messages=new ActionMessages();
* messages.add("register",new
* ActionMessage("missing.key",userName,firstname));
* messages.add("reg",new ActionMessage("label.hello",firstname));
* saveMessages(request, messages); MessageResources messageResources =
* getResources(request); ActionErrors actionErrors = new
* ActionErrors(); actionErrors.add("error", new
* ActionMessage("missing.key",
* messageResources.getMessage("label.UserName"), messageResources
* .getMessage("label.Age"))); saveErrors(request,actionErrors);
*/
System.out.println("Forwarding to.. Success !!");
return mapping.findForward("success");
}
}
can any body give me the solution for this