1

i'm new to java and have a strange problem. i create some folder(theme, js, css) in WEB-INF folder and put my files to this folders. in index.jsp i use a css file by following way:

<style type="text/css"> 
        <%@include file="WEB-INF/css/style.css" %>
 </style>

it works good. but in style.css file i have a div tag that set a background for header tag by following way:

#header{
background: url(../theme/violet/header.jpg) repeat-x;
}

oh. my problem is here. it doesn't work. since other css command work very good. i know that WEB-INF detail aren't accessible but may there is a way like the way that i use for link style.css in my index.jsp page.

any solution? thanks.

rasoul
  • 45
  • 1
  • 5
  • Just add inside WEB-INF css folder, like you did, inside this folder add images folder and put that header.jpg there. Your image will be available for style.css - path for background: url(images/header.jpg) repeat-x; btw this image will be available for everyone outside (if you precise exact path in url) but entire folder image or css won't be, because it's protected by server or app container like tomcat - you can change it inside config files (/conf/web.xml). Tomcat inside context.xml has monitored resources that is valuable too – blueberry0xff Aug 03 '14 at 10:36

3 Answers3

2

From the way you include style.css, I guess your index.jsp is outside the WEB-INF folder which can be accessed directly by client browser. The reason the included style.css works fine is because it is included on the server-side. But in the style.css, to get the background image, the browser will launch a new connect to the image which happens to be inside the WEB-INF folder and the server refuse to send it back and you are doomed.

If you have a centralized controller servlet, you can put your jsps inside the WEB-INF folder to prevent it from accessed directly. Your servlet will redirect all request to appropriate jsp according to request parameters.

As far as I can tell, there is no absolute reason to put images, JavaScripts etc inside this folder, you will definitely run into problems when the browser need to access this folder to retrieve data.

dragon66
  • 2,645
  • 2
  • 21
  • 43
1

That is not possible. If you want content directly accessible from a browser it can not reside inside WEB-INF.

Mark Thomas
  • 16,339
  • 1
  • 39
  • 60
  • what's the meaning of your answer. you will say i most put my resource files in out of WEB-INF? therefore how my jsp file can access to css file, but css file cann't have access to image file? is meaninig of your answer that css file process by web browser? – rasoul May 03 '12 at 19:14
  • If you want a resource (such as header.jpg) to be accessible by clients such as browsers it cannot be located inside WEB-INF – Mark Thomas May 03 '12 at 19:16
0

Why you create theme, js, css in WEB-INF Folder? WEB-INF directory contains metadata about the application. During normal operations, you should not need to modify anything under the WEB-INF directory.

you can create theme, js, css folder under war or WebContent directory directly it will easy to use in your jsp pages.

this link will help you.

Dipesh Gandhi
  • 765
  • 1
  • 13
  • 31
  • in a book i read that he offer a structure for website. author says it's good that you put your css, theme, js and tld in WEB-INF. ofcourse he says that all data in WEB-INF are unaccessible from user but webserver allows to your classes that cas use its(probably he will say our classes can use it, not all source such jsp file, i dont know). – rasoul May 03 '12 at 19:23