webinf下jsp访问css_如何才能访问放在WEB-INF文件夹中的文件

bd96500e110b49cbb3cd949968f18be7.png

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:

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.

解决方案

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值