如何才能访问放在WEB-INF文件夹中的文件 [英] how can i have access to my files that placed in WEB-INF folder

查看:986
本文介绍了如何才能访问放在WEB-INF文件夹中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是java的新手并且有一个奇怪的问题。
我在WEB-INF文件夹中创建一些文件夹(主题,js,css)并将我的文件放到这个文件夹中。 index.jsp中的
我按照以下方式使用css文件:

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>

它运作良好。
但在style.css文件中我有一个div标签,通过以下方式设置标头标签的背景:

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;
}

哦。我的问题在这里。它不起作用。因为其他css命令工作得很好。
i知道WEB-INF细节不可访问,但可能有一种方法,就像我在index.jsp页面中用于链接style.css的方式。

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.

推荐答案

从包含style.css的方式来看,我猜你的index.jsp在WEB之外-INF文件夹,可以通过客户端浏览器直接访问。包含style.css正常工作的原因是因为它包含在服务器端。但是在style.css中,为了获得背景图像,浏览器将启动一个新的连接到图像,该图像恰好位于WEB-INF文件夹内,服务器拒绝将其发送回来,你注定要失败。

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.

如果你有一个集中控制器servlet,你可以将你的jsps放在WEB-INF文件夹中,以防止它被直接访问。你的servlet会根据请求参数将所有请求重定向到适当的jsp。

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.

据我所知,没有绝对的理由将图像,JavaScripts等放在这个文件夹中,当浏览器需要访问此文件夹以检索数据时,您肯定会遇到问题。

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.

这篇关于如何才能访问放在WEB-INF文件夹中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆