rasoul
rasoul

Reputation: 45

how can i have access to my files that placed in WEB-INF folder

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.

Upvotes: 1

Views: 8545

Answers (3)

dragon66
dragon66

Reputation: 2715

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.

Upvotes: 2

Dipesh Gandhi
Dipesh Gandhi

Reputation: 765

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.

Upvotes: 0

Mark Thomas
Mark Thomas

Reputation: 16660

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

Upvotes: 1

Related Questions