maven - How to link a web resource file from /main/resources in JSP? -
i have following structure in java webapp
-- main -- java -- resources -- lib -- css -- style.css -- webapp -- web-inf -- web.xml --index.jsp
how can link style.css index jsp?
<link rel="stylesheet" href="???">
what should here?
thanks in advance
the maven /main/resources
folder classpath resources not represent java classes, such i18n properties files , kinds of configuration files (text, xml, json, etc). resources you'd obtain via classloader#getresourceasstream()
.
that folder not intented public web resources (i.e. files accessible public http://xxx
url). you're supposed put web resource files in maven /main/webapp
folder (outside /web-inf
, /meta-inf
), correctly did jsp file (which public web resource).
so, move /lib
folder down (i'd rename folder e.g. "resources", "assets", or "static", more conform de facto standards; "lib" folder name namely suggests it's full of jar files).
main |-- java |-- resources `-- webapp |-- lib | `-- css | `-- style.css |-- web-inf | `-- web.xml `--index.jsp
given structure, example deployment context path of /webapp
, , example server running on http://localhost:8080
, css file should accessible on below absolute url:
so, of below css links in html representation of jsp page should do:
<link rel="stylesheet" href="http://localhost:8080/webapp/lib/css/style.css" />
<link rel="stylesheet" href="//localhost:8080/webapp/lib/css/style.css" />
<link rel="stylesheet" href="/webapp/lib/css/style.css" />
<link rel="stylesheet" href="${pagecontext.request.contextpath}/lib/css/style.css" />
take pick. last 1 recommendable given dynamicness of other parts of target url.
Comments
Post a Comment