Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using getText() for the getting property in Struts 2

I am working on the Struts2 framework with JSP.

In my samplePrj.properties file, in that

com.samplePrj.Successmessage = Saved Successful

is an attribute. I need to use this value in my JSP page, using Struts2.

so how can I get the value of "com.samplePrj.Successmessage" in my JSP page.

like image 984
hKs Avatar asked Nov 22 '25 11:11

hKs


2 Answers

Use the text tag

<s:i18n name="samplePrj">
    <s:text name="com.samplePrj.Successmessage" />
</s:i18n>

it will load the bundle using i18n tag from samplePrj.properties and print the value from key com.samplePrj.Successmessage in it.

or you can use it with getText() but your action class should extend ActionSupport.

<s:property value="getText('com.samplePrj.Successmessage')"/>
like image 70
Roman C Avatar answered Nov 24 '25 00:11

Roman C


You can use getText() method to read from properties files.

<s:set var="variable" value="getText('com.samplePrj.Successmessage')"/>
<s:if test="myVariable == #variable"> 
  //do what u want
</s:if>

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!