如何将我的CSS连接到我的JSP文件存储在WEB-INF文件夹? Websphere / JSP [英] how can i connect my css to my JSP files stored in the WEB-INF folder? Websphere/JSP
问题描述
我正在使用ibm websphere并创建一个动态网络项目。所有的 JSP
文件都在我的WEB-INF文件夹中,我在我的 web.xml
文件中使用servlet映射使他们可以访问。这到目前为止工作正常。但我有我的CSS的问题。一如往常,我的 CSS
文件位于名为css的文件夹中的 WebContent
中。为我的 jsp
I am using ibm websphere and creating a Dynamic web project. All of my JSP
files are in my WEB-INF folder and i use servlet mapping in my web.xml
file to make them accessible. This has worked fine so far. however i have problem with my CSS. as always, my CSS
file is located in WebContent
in a folder named css. heres my link for my jsp
<link rel="stylesheet" href = "css/styles.css">
我没有运气让我的css显示...
I'm having no luck getting my css to show...
what am i missing?
推荐答案
生成的HTML输出中的相对URL是由浏览器相对于请求URL解释的你在浏览器的地址栏中看到),而不是他们在服务器的磁盘文件系统中的物理位置。这就是webbrowser谁必须通过HTTP请求下载它们,它不是网络服务器谁必须从某种方式包括他们从磁盘。
The relative URLs in the generated HTML output are by the browser interpreted relative to the request URL (as you see in browser's address bar), not to their physical location in the server's disk file system. It's namely the webbrowser who has got to download them by a HTTP request, it's not the webserver who has got to include them from disk somehow.
其中的一种方法是请使用这些资源的域相对路径,即以 /
开头。您可以使用 $ {pageContext.request.contextPath}
动态内联当前webapp的上下文路径。
One of the ways is to use a domain-relative path for those resources, i.e. start with /
. You can use ${pageContext.request.contextPath}
to dynamically inline the current webapp's context path.
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/styles.css">
这将在生成的HTML输出中结束,如下所示:
This will end up in the generated HTML output as follows:
<link rel="stylesheet" href="/yourContextPath/css/styles.css">
这样浏览器就能正确下载。
This way the browser will be able to download them properly.
- Browser can't access CSS and images when calling a Servlet which forwards to a JSP
这篇关于如何将我的CSS连接到我的JSP文件存储在WEB-INF文件夹? Websphere / JSP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!