문제

I need to access from the jsp files which are in WebContent/jsp folder, to the *.css file which is in WebContent/css.

And I've tried using link rel="stylesheet" type="text/css" href="../css/adminStyle.css". But, sometimes the *.css works and sometimes it doesn't.

Another thing is how do I access from a *.css file to an image in imgs folder. And I tried using background-image:url('../imgs/background.png');

The hierarchy is the following:

WebContent

 css
  |
  +--->  adminStyle.css

 imgs
  |
  +--->  background.png

 jsp
  |
  +--->  admin.jsp
도움이 되었습니까?

해결책

"sometimes the css works and sometimes not" looks like you it works for some url and doesn't work for some url. for this @rickz answer will work

href="${pageContext.request.contextPath}/css/adminStyle.css"

This will eliminate the possibility of breaking css import with regards of url

for second question "how do I access from a css file to an image in imgs folder"

background-image:url('../imgs/background.png');

because relative path of background image defined in css will start from the folder where your css file is.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top