开发者

How to create dynamic images with struts2?

开发者 https://www.devze.com 2022-12-27 23:53 出处:网络
In strut2, the <s:img> tag is gone. How can I create dynamic images? Update I want to set the image \'src\' according to a parameter in the value stack (like ${userName_开发者_运维技巧}).I did

In strut2, the <s:img> tag is gone. How can I create dynamic images?

Update

I want to set the image 'src' according to a parameter in the value stack (like ${userName_开发者_运维技巧}).


I did a search on the struts2's offical website and found they doesn't provide a dynamic image tag. There is a struts2 image plug which provide this, however it is in alpha stage. http://code.google.com/p/s2-image/. At last, I had to do this in pure JSP codes.

Update Gashhh...There is another simple way by using <img src=<s:text name="genTP" /> />. But I think is quite strange.


No need for a specific tag. You just use the plain html tag <img src="..."> , the src attribute pointing to the static/dynamic url that gives you the image.

Now, if the url points to an action in your same Struts2 webapp, you'll want to code an action that returns a dynamic image instead of a html page. In that case, you should read about the Stream result... if you can find anything useful in the official page/wiki (sigh... the docs are messed out at this moment, do yourself a favour and buy "Struts2 in Action"). The concept is quite clean once you grasp it. See for example:

http://www.javahowto.net/struts2/dynamic-mime-type-on-stream-result-struts-2/

0

精彩评论

暂无评论...
验证码 换一张
取 消