我将图像放在 /webapp/img/test.png 下,但它不会在 jetty 中渲染

发布于 2025-01-02 13:25:33 字数 567 浏览 3 评论 0原文

我添加了一个 asset 文件夹和一个 images 子文件夹:

/webapp/assets/img

并在里面放置了一个 test.png 文件。

在我的 index.jsp 页面中,我放置了一个 img 标签:

<img src="/assets/img/test.png" alt="" />

The image doest' render, I run:

mvn clean install

mvn jetty:run

在终端窗口的输出中,我看到:

20:30:42,905 WARN PageNotFound:947 - 没有找到 HTTP 请求的映射DispatcherServlet 中名称为“myapp”的 URI [/assets/img/test.png]

我也看到 favicon.ico 出现相同的错误(我没有'这样的错误) 感觉)。

我需要调整 web.xml 文件中的某些内容吗?

(这是一个spring mvc应用程序)

I added a assets folder and an a images subfolder:

/webapp/assets/img

And inside I put a test.png file.

From inside my index.jsp page, I put a img tag:

<img src="/assets/img/test.png" alt="" />

The image doesnt' render, I ran:

mvn clean install

mvn jetty:run

In the output in my terminal window I see:

20:30:42,905 WARN PageNotFound:947 - No mapping found for HTTP request with URI [/assets/img/test.png] in DispatcherServlet with name 'myapp'

I also see the same error for favicon.ico (I dont' have one so that one makes sense).

Do I need to adjust something in my web.xml file?

(This is a spring mvc app)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

江城子 2025-01-09 13:25:33

您可能已将 Spring servlet 配置为映射到 /,这意味着它处理对 Web 应用程序的所有请求。要么将其仅映射到某些请求(例如 *.htm、*.action 或其他),要么 配置 Spring 提供静态资源

You have probably configured the Spring servlet to be mapped to /, which means it handles all the requests to the web app. Either map it to only certain requests (like *.htm, *.action, or whatever), or configure Spring to serve static resources.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文