سؤال

I have an image images/example.jpg in the Struts2 project folder.

I am able to display this image by using:

<s:url value="/images/example.jpg" var="urlTag"></s:url>
<img src="<s:property value="#urlTag"/>" height="200" width="200"/>

But how to set the URL- value attribute dynamically? I tried doing this:

<s:url value="<s:property value="imageLink"/>" var="urlTag"></s:url>  
/* where "imgageLink" has the value(/images/example.jpg) obtained from the action class*/
<img src="<s:property value="#urlTag"/>" height="200" width="200"/>

The above code gives an error:

org.apache.jasper.JasperException: /display.jsp (line: 28, column: 45) equal symbol expected

(i.e. before imageLink in the above code)

Please suggest any solutions for this.

Note: I have successfully done image transfer using inputstream, but I rather want to work it out using Struts url tag.

هل كانت مفيدة؟

المحلول

You can't place struts tags in the struts tag attribute. Try

<s:url value="%{imageLink}" var="urlTag"/>

provide the getImageLink() in the action class.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top