使用SPRING MVC在JSP中显示图像 [英] Display image in JSP with SPRING MVC
问题描述
我正在尝试在 jsp
上显示图像。
我的图片文件位于
I am trying to display an image on a jsp
.
My image file is located at
MyApp/WebContent/images/logo.jpg
我的JSP页面位于
And my JSP pages are located at
MyApp/WebContent/WEB-INF/view/home.jsp
我有已经尝试使用图像
<'img src="<%=request.getContextPath()%>/images/logo.jpg" />
和
<'img src="<'c:url value='<%=request.getContextPath()%>/images/logo.jpg'></c:url></img>
这个问题是因为我的位置层次结构放置了我的图像吗?
Is this issue something because of my location hierarchy where I have placed my image?
非常感谢您的帮助。谢谢。
Really appreciate your help. Thank you.
更新:
我找到了解决我问题的方法:
http://www.tutorialspoint.com/spring/spring_static_pages_example.htm
I've found the solution to my problem in: http://www.tutorialspoint.com/spring/spring_static_pages_example.htm
我只需要在我的<$ c $中使用资源映射c> servlet.xml 。
我非常感谢您的所有答案。:)
I really appreciate all of your kind answers. :)
推荐答案
任何静态资源也在spring mvc中查找URL Mapping,因此应在 springmvc-servlet.xml中定义静态资源
。
Any static resource is also look for a URL Mapping in spring mvc, so static resources should be defined in the springmvc-servlet.xml
.
将以下条目添加到MVC配置中。我假设你的静态文件在 resources
文件夹中。
Add the following entry to your MVC configuration. I assume that your static files in resources
folder.
<mvc:resources mapping="/resources/**" location="/resources/" />
然后可以从页面访问静态文件。
then static files can be accessible from the page.
<img src="/resources/images/logo.jpg" />
这篇关于使用SPRING MVC在JSP中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!