Solved

How to getResources() in a JSP page?

Posted on 2004-04-12
12
1,282 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
12 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 92

Accepted Solution

by:
objects earned 50 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
For cloud, the “train has left the station” and in the Microsoft ERP & CRM world, that means the next generation of enterprise software from Microsoft is here: Dynamics 365 is Microsoft’s new integrated business solution that unifies CRM and ERP fun…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now