问题描述
我有一个 struts2 动作,它有一个我想在 jsp 页面中显示的图像的变量.当我使用以下内容显示变量的值时:
i have a struts2 action which has a variable for an image which i want to display in a jsp page. when i display the value of the variable using the following:
<s:property value="variableName" />
我得到图像文件的绝对路径.
i get the absolute path of the image file.
但是当我尝试以下操作时:
but when i try the following:
<img src='<s:property value="variableName" />' />
我在那里得到一个空白.我什至尝试过以下方法:
i get a blank there. i have even tried the following:
<img src="${variableName}" />
我做了一些思考.设置的图像路径在tomcat的临时文件夹中.是因为我无法访问它吗?
i have done some thinking. the path of the image which is set is in temp folder of tomcat. is it because of that that i am unable to access it?
没有效果.这可能是什么问题?
to no effect. what may be the issue in this?
推荐答案
img
标签的src
必须包含绝对路径,才能指向来自客户端计算机的图像文件.
The src
of the img
tag must contain an absolute path, then only it can point to the image file from the client machine.
如果variableName
包含这样的绝对路径
If the variableName
contains an absolute path like this
http://localhost/images/pics/icon.gif
img
将从服务器中找到图像.因此始终可用,因此您可以使用它.
The img
will finds the image from the server. Thus available always an hence you can use this.
<img src="${variableName}"/>
如果 variableName
是一个相对路径,即;服务器可识别的东西.
If the variableName
is a relative path ie; something that's recognisable for the server.
/images/pics/icon.gif
上述路径将由服务器识别,但不会从远程机器识别.在这种情况下,你需要有这个
The above path will be identified by the server but it wont be identified from the remote machine. In that case you need to have this
<img src="<c:url value=variableName/>" />
这篇关于从struts2动作变量中的路径在jsp中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!