Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to getResources() in a JSP page?

Posted on 2004-04-12
12
Medium Priority
?
1,420 Views
Last Modified: 2012-05-04
In my JSP page, I want to get a text in ApplicationResources.properties file. The code is somehow likes this below:

Locale locale = (Locale) session.getAttribute(Action.LOCALE_KEY);
MessageResources messages = servlet.getResources();
String message = getMessage(locale,"important.message");

---> cannot resolve the object  servlet  and function  getMessage().

how to solve this problem?

Thanks in advance.
thungrac02
0
Comment
Question by:thungrac02
  • 5
  • 5
10 Comments
 
LVL 92

Expert Comment

by:objects
ID: 10810770
try:

MessageResources messages = Resource.getResources(request);
String message = messages.getMessage(locale,"important.message");
0
 

Author Comment

by:thungrac02
ID: 10811047
Hi objects!
What are libraries must be imported?
0
 
LVL 92

Expert Comment

by:objects
ID: 10811081
org.apache.struts.util.MessageResources
org.apache.struts.validator.Resources
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:thungrac02
ID: 10811255
It still cannot resolve Resource.
0
 

Author Comment

by:thungrac02
ID: 10811663
In a JSP file, we cannot get a string in ApplicationResources.properties file???
0
 
LVL 92

Accepted Solution

by:
objects earned 200 total points
ID: 10812105
sorry that should be:

MessageResources messages = Resources.getResources(request);
0
 

Author Comment

by:thungrac02
ID: 10819498
Hi objects!

I found that if I want  Resources.getResources(request)  takes effect, my file must extends Action class: public class TestAction extends Action {...}

so in a JSP file we cannot get a String from ApplicationResources.properties file, unfortunately.
0
 
LVL 92

Expert Comment

by:objects
ID: 10819529
> I found that if I want  Resources.getResources(request)  takes effect, my file must extends Action class

why?
0
 

Author Comment

by:thungrac02
ID: 10819976
Because getResources() is a method  of Class Action.
My solution is: create a .java file

import com.ibm.ett.util.struts.RecordAction;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.util.MessageResources;
import java.util.Locale;

public class Properties extends RecordAction {
    HttpServletRequest request = null;
    public String getMessage(String key) {
        MessageResources messages = getResources(request);
        String message = messages.getMessage(key);
        return message;
    }
    public String getMessage(Locale locale, String key) {
        MessageResources messages = getResources(request);
        String message = messages.getMessage(locale, key);
        return message;
    }
    public Properties(HttpServletRequest request){
        this.request = request;
    }
}

then in my JSP file, I can get a String from ApplicationResources.properties file:

      Properties properties = new Properties(request);
      String foreTitle = properties.getMessage("forTitle.reportB11");

and it works well.
0
 
LVL 92

Expert Comment

by:objects
ID: 10819998
> Because getResources() is a method  of Class Action.

It is but thats not the method I used above :)
I used the getResources() method in the Resouces class.
 
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will be showing you how to subnet the easiest way possible for IPv4 (Internet Protocol version 4). This article does not cover IPv6. Keep in mind that subnetting requires lots of practice and time.
LinkedIn blogging is great for networking, building up an audience, and expanding your influence as well. However, if you want to achieve these results, you need to work really hard to make your post worth liking and sharing. Here are 4 tips that ca…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month20 days, 16 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question