java - Spring 4 - MVC - URL param and static resource path -


i have spring mvc application, in page list "group" details in table, fetched database. url of every group set "/viewgroup/410", 410 groupid loaded database , displayed in viewgroup.jsp page.

<td><a href="viewgroup/${group.groupid}">${group.name}</a></td> 

so, controller method has

@requestmapping("/viewgroup/{groupid}")  public string viewgroup() {     ... } 

like this. jsp pages not load static resources have in directory structure

+webapp   +resources      +css      +js      +images   +views     +login.jsp 

the jsp pages has below path image/js/css.

<link href="resources/css/bootstrap.css" rel="stylesheet" media="screen"> 

i tried adding

@controller @requestmapping("/viewgroup/**") public class viewgroupcontroller {    ... } 

and in jsp

<link href="viewgroup/resources/css/bootstrap.css" rel="stylesheet" media="screen"> 

still jsp page loads not load static resources. how provide resource path of static resources in jsp pages when pass params in url?

the fact pass query parameters through url of project not affect way addresses static resources. need include link static resources (as relative path example) follow :

<link href="/resources/css/bootstrap.css" rel="stylesheet" media="screen"> 

the resolution of such static resources independent of page you're looking at, /viewgroup/410 or /foo/bar. that's reason why don't need "viewgroup" @ beginning of link's href.

but need tell spring mvc how should address such static resources. usually, done in spring configuration. example, if use spring mvc java config through webmvcconfigurer instance, should override addresourcehandlers method in such way :

    @override     public void addresourcehandlers(resourcehandlerregistry registry) {         registry.addresourcehandler("/resources/**").addresourcelocations("/resources/");     } 


edit : bad, thought spring mvc + view technology (jsp, thymeleaf, etc etc) automatically resolve link's href against root path of web-app not true raw html relative link's href resolved against current path. in end, found op, links resolved against root path if processed view technology in use (in example jsp : <c:url value="/resources/css/bootstrap.css"/>)


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -