thungrac02
asked on
How to getResources() in a JSP page?
In my JSP page, I want to get a text in ApplicationResources.prope rties file. The code is somehow likes this below:
Locale locale = (Locale) session.getAttribute(Actio n.LOCALE_K EY);
MessageResources messages = servlet.getResources();
String message = getMessage(locale,"importa nt.message ");
---> cannot resolve the object servlet and function getMessage().
how to solve this problem?
Thanks in advance.
thungrac02
Locale locale = (Locale) session.getAttribute(Actio
MessageResources messages = servlet.getResources();
String message = getMessage(locale,"importa
---> cannot resolve the object servlet and function getMessage().
how to solve this problem?
Thanks in advance.
thungrac02
ASKER
Hi objects!
What are libraries must be imported?
What are libraries must be imported?
org.apache.struts.util.Mes sageResour ces
org.apache.struts.validato r.Resource s
org.apache.struts.validato
ASKER
It still cannot resolve Resource.
ASKER
In a JSP file, we cannot get a string in ApplicationResources.prope rties file???
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi objects!
I found that if I want Resources.getResources(req uest) 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.prope rties file, unfortunately.
I found that if I want Resources.getResources(req
so in a JSP file we cannot get a String from ApplicationResources.prope
> I found that if I want Resources.getResources(req uest) takes effect, my file must extends Action class
why?
why?
ASKER
Because getResources() is a method of Class Action.
My solution is: create a .java file
import com.ibm.ett.util.struts.Re cordAction ;
import javax.servlet.http.HttpSer vletReques t;
import org.apache.struts.util.Mes sageResour ces;
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(HttpServletRequ est request){
this.request = request;
}
}
then in my JSP file, I can get a String from ApplicationResources.prope rties file:
Properties properties = new Properties(request);
String foreTitle = properties.getMessage("for Title.repo rtB11");
and it works well.
My solution is: create a .java file
import com.ibm.ett.util.struts.Re
import javax.servlet.http.HttpSer
import org.apache.struts.util.Mes
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
return message;
}
public Properties(HttpServletRequ
this.request = request;
}
}
then in my JSP file, I can get a String from ApplicationResources.prope
Properties properties = new Properties(request);
String foreTitle = properties.getMessage("for
and it works well.
> 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.
It is but thats not the method I used above :)
I used the getResources() method in the Resouces class.
MessageResources messages = Resource.getResources(requ
String message = messages.getMessage(locale