Question

I have created simple HelloWorld project from Spring MVC template in Spring STS.

I found that there is a HomeController bean, which decides, which JSP to call and prepares information for it. As I see, this class associates HTTP request with it's method.

So, now I need to have some images or javascript files to be loaded into my page. But HomeController in template configuration does not allow this.

What is the simplest way to provide browser access to some folder on the server? What if I remove HomeController at all, will DefaultServlet come in action?

Was it helpful?

Solution

<mvc:resources mapping="/static/**" location="/static/" />

Where

  • mapping is the URL at which the resources will be accessible: /static/main.css
  • location is the webapp-root relative location of the files.

You can have more than one <mvc:resources> tags. See here for more infomration

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top