Skip to content
Advertisement

How to get source path and alternate text values from properties file in Struts2 for inserting images? In Struts1 altKey and srcKey were used for this

I would like to know what the replacement is for the altKey and srcKey attributes in the <html:img> tag in Struts 2.

What I want to achieve is to be able to insert an image with source path from properties file. Similar to what srcKey does in Struts1.

And even for the altertnate text, I want to know how to get that from the properties file like the altKey in Struts1.

<s:url var="url" value="/image/test.jpg"/>
<img src="${url}" border="0" alt="Test">

This works but the source for image is directly mentioned here. I would want to get that value from the properties file.

I want to migrate the below code to Struts 2. How do I do this?

<html:img width="10" height="10" align="middle" altKey="alt.logo" srcKey="image.logo" />

Advertisement

Answer

Your action class should extend ActionSupport. Then you can use something like

<s:url var="url" value="%{getText('image.logo')}"/>
<img src="${url}" border="0" alt="<s:text name='alt.logo'/>">
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement