Does Spring MVC support extension-less URLs?

2020-04-10 01:47发布

Does Spring MVC support extension-less URLs like asp.net MVC does?

I am just getting started with Spring MVC.

Or maybe has nothing to do with Spring MVC but Tomcat?

2条回答
smile是对你的礼貌
2楼-- · 2020-04-10 01:58

You must set this in your /WEB-INF/web.xml:

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

(assuming your DispatcherServlet is named "dispatcher").

查看更多
Summer. ? 凉城
3楼-- · 2020-04-10 02:17

Yes, it does.

If you are using annotations, you annotate your controller methods or classes with something like:

@RequestMapping("/hello")

Which will respond to /hello when you map the dispatcher servlet like so:

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
查看更多
登录 后发表回答