• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

从struts2动作变量的路径在jsp显示图像

用户头像
it1352
帮助3

问题说明

我有一个 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='https://www.it1352.com/<s:property value="variableName" />' />

我在那里得到一个空白.我什至尝试过以下方法:

i get a blank there. i have even tried the following:

<img src="https://www.it1352.com/${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?

正确答案

#1

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="https://www.it1352.com/${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="https://www.it1352.com/<c:url value=variableName/>" />

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcbcceg
系列文章
更多 icon
同类精品
更多 icon
继续加载