简体   繁体   中英

Mapping resources with Spring MVC

I first setup Spring MVC to handle all urls.

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

And the dispatcher servlet mapped resources.

<mvc:resources mapping="/resources/**" location="/VAADIN/resource/" />

This worked fine, but now I want to change Spring so that it only handle's '/search/' URLs.

<servlet-mapping>
    <servlet-name>HelloWeb</servlet-name>
    <url-pattern>/search/*</url-pattern>
</servlet-mapping>

This works but my resources no longer work. I think it's because it's looking for the resources in /search/resources rather than /resources. But I'm not sure.

Anyone have any idea why this is happening?

Thanks!

You can make your static resources visible , configure the static resources in your web.xml .

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/VAADIN/resource/*</url-pattern>
</servlet-mapping>

If VAADIN is the project name , need not specify it here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM