在JSP中加载一个img [英] Load an img in a JSP
问题描述
<$ c $我试图在JSP中加载一个动态图像,我试图做这样的事情: c>< img src =<%= book.img%>>
其中book.img包含一个字符串(绝对路径)。我该如何解决这个问题?
我收到的错误如下:
元素img上属性src的错误值:PATH中的DOUBLE_WHITESPACE。
因此,如果您的图片存储在:
Webcontent / resources / images /
你有一张图片:
close-button.png
book.img
should = /resources/images/close-button.png
然后在JSP中使用JSTL创建URL:
< img src =< c: url value =$ {book.img}/>/>
c:url
上下文到绝对url。
没有JSTL的另一种方法是:
< img src =$ {pageContext.request.contextPath} $ {book.img}/>
I'm trying to load an image dynamicaly in a JSP and I'm trying to do something like:
<img src="<%= book.img %>">
where book.img contains a string (an absolute path). How can I fix the problem?
The error I receive is the following:
Bad value for attribute src on element img: DOUBLE_WHITESPACE in PATH.
book.img
should contain an absolute url to the image on the server.
So if your images are stored in:
Webcontent/resources/images/
and you had an image:
close-button.png
book.img
should = /resources/images/close-button.png
Then in your JSP use JSTL to create the URL:
<img src="<c:url value="${book.img}"/>"/>
c:url
will prefix the domain and context to the absolute url.
Another way without JSTL is:
<img src="${pageContext.request.contextPath}${book.img}"/>
这篇关于在JSP中加载一个img的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!