使用 SPRING MVC 在 JSP 中显示图像 [英] Display image in JSP with SPRING MVC

查看:44
本文介绍了使用 SPRING MVC 在 JSP 中显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 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

我只需要在我的 servlet.xml 中使用资源映射.

I just have to use resource mapping in my 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆