【发布时间】:2014-10-22 19:03:12
【问题描述】:
我的代码如下:
<td width="24px">
<img src="${pageContext.request.contextPath}/images/success.gif"/>
</td>
我的 gif 文件位于位置
\src\main\webapp\图像
当我尝试使用 Spring MVC 框架加载图像时,它不会加载图像。
我尝试给出路径
<img src="images/success.gif/">
<img src="webapp/images/success.gif/">
查看源代码:
<img src="/MyProject-UX/images/success.gif">
我的 spring 配置文件:
<context:component-scan base-package="com.mycompany"/>
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/"/>
<property name="suffix" value=".jsp"/>
</bean>
@Controller
@RequestMapping("/closeWindow")
public class ClosingWindow {
@RequestMapping(method = RequestMethod.GET)
public String printHello(ModelMap model) {
return "closeWindow";
}
【问题讨论】:
-
那么生成的html是什么样子的呢?您必须在
src中添加什么内容才能加载该图像?这会告诉你修复代码需要做什么。 -
successbean 是什么?它的getGif()方法返回什么?你可能想要${pageContext.request.contextPath}/images/success.gif。 -
编辑:但您没有更新输出。更新后的代码无法产生给定的输出。您仍然缺少
/。 -
@JBNizet,我再次更新了上面的代码。
-
好的。所以有什么问题。生成的 HTML 现在是正确的。图像的位置是否正确?调度程序 servlet 是否映射到
/?
标签: html jsp spring-mvc