• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Message Resources

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A couple of thing:

1) Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information. You can go back and change your post to add code tags by clicking the .

2) Please take the time to choose the correct forum for your posts. For more information, please read this.

This post has been moved to the Struts forum.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Show us how you configured your message resources in the struts-config.xml file and also post extracts from the contents of those files as well as telling us where the files are located.
 
chittapuram sai Prashanthi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Struts-Configuration file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>


<form-beans>
<form-bean name="regForm" type="com.RegForm" />
</form-beans>

<!-- Action Mapping Configuration -->
<action-mappings>
<action path="/welcome" name="regForm" type="com.RegAction"
input="/reg.jsp">
<forward name="success" path="/success.jsp" />
<forward name="failure" path="/failure.jsp" />
</action>
</action-mappings>



<!-- Message Resources Configuration -->
<message-resources key="resource1"
parameter="ApplicationResources_en" />
<message-resources key="resource2" parameter="UserResources" />

</struts-config>



the path of the application resources files

source/Application Resources.properties.
source/User Resources.properties.
 
chittapuram sai Prashanthi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please this is very urgent if any body knows the solution please post it immediately
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, the parameter you specify in the message-resources stanza of the struts-config.xml file should be absent any language suffix. You therefore need to change your entry to:


Secondly, the resources files need to be in the classpath. Make sure that they get copied from the source folder to the WEB-INF/classes folder when the project is built.

Thirdly, I'm not sure if you just mis-typed them in your post, but when you listed the location of the files, they have a space in the name. Make sure they do not have any spaces in them. (ApplicationResources.properties not Application Resources.properties)
[ September 26, 2008: Message edited by: Merrill Higginson ]
 
chittapuram sai Prashanthi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got the answer actually there is no need of placing the resource files in classes folder it is enough if we put it in the source folder,I have got the output after including the property attribute in the <html:messages> tag[/B]
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by chittapuram sai Prashanthi:
there is no need of placing the resource files in classes folder it is enough if we put it in the source folder[/B]


For the sake of anyone else reading this, the above statement is not true. If you're using an IDE such as Eclipse, copying the properties files from the source folder to the classes folder is done automatically, but when the application is deployed, the properties files must be in the classes directory or they won't be found.
reply
    Bookmark Topic Watch Topic
  • New Topic