Spring MVC网址映射 [英] Spring MVC url-mapping

查看:128
本文介绍了Spring MVC网址映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用Spring mvc制作了一个简单的Web应用程序.

I made a simple web application by Spring mvc.

我要使用这些URL

  • /用户
  • /user/{id}
  • /user/create
  • /user/edit/{id}

在web.xml中

第一种情况

<servlet-mapping> 
    <servlet-name>SpringMVC1</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 

效果很好.
但我看不懂 http://localhost:8080/res/images/image.png -404错误
在{我的项目路径}/WebContent/res/images/logo.png

It works well.
but I can not read http://localhost:8080/res/images/image.png - 404 error
in {my project path}/WebContent/res/images/logo.png

第二种情况

<servlet-mapping> 
    <servlet-name>SpringMVC1</servlet-name> 
    <url-pattern>/*</url-pattern> 
</servlet-mapping> 

我可以在 http://localhost:8080/res/images/image.png上看到图像 但是 http://localhost:8080/user/create -404错误

I can see image on http://localhost:8080/res/images/image.png but http://localhost:8080/user/create - 404 error

怎么了?

推荐答案

您的XML需要这样的内容:

You need something like this in your XML:

<mvc:resources mapping="/res/**" location="/path/to/your/resources"/>

请参见 16.14.5.配置资源服务

这篇关于Spring MVC网址映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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