Morning,
Having issues mapping a controller to / (i.e. localhost:8080/someApp/ would map to @Controller("/")) while also using mvc:resources
web.xml mapping:
<servlet-mapping>
<servlet-name>springServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
mvc:resources
<mvc:resources mapping="/resources/**" location="/resources/" />
The server loads the page correctly, but when I map to an asset i.e.
<link type="text/css" rel="stylesheet" href="<c:url value="/resources/css/blueprint/print.css"/>" />
When clicking the css file via view-source in a web browser, the server response maps back to the index page, rather than the resource. Leads me to believe it's related to the servlet-mapping.
Any help with this would be great!
Thanks!
Edit: Forgot to mention, if I bind the controller to say:
@Controller("/pages")
Everything works fine, just would rather have the context root be able to respond correctly.
@Controller("/)
and
@RequestMapping("/")
are not the same thing.
Since @RequestMapping may be placed at a class level, placing the mapping on the class will have the desired affect.
Example:
@Controller
@RequestMapping("/")
public class RootController
{
@RequestMapping(method=RequestMethod.GET)
public String index()
{
return "index";
}
}
This will work correctly, and also works with the mvc:resources bean.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With