无法在JSP页面中加载外部CSS [英] Unable to Load external CSS in JSP page

查看:145
本文介绍了无法在JSP页面中加载外部CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的jsp页面中加载外部CSS页面,但是通常的做法无济于事,是否有任何遗漏之处?

I am trying to loading an external css page in my jsp page but the usual way of doing it doesnt help , Is there anything that am missing out ?

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">


 <title>Login Page</title>
<head>

    <link rel="stylesheet" type="text/css" href="style.css"/>
</head>

推荐答案

链接元素中的href指定一个相对于URL的路径,该路径仅在css文件与JSP位于同一文件夹中且如果直接寻址JSP.

The href in your link element specifes a URL-relative path that will only work if the css file is in the same folder as the JSP and if the JSP is directly addressed.

由于您已经提到cssJSP在同一目录中.检查您如何处理JSP.

Since you have mentioned that css is in the same directory as JSP. Check how you are addressing JSP.

您需要将上下文路径插入Web应用程序(例如/webapp/styles.css),或者使用相对路径或使用HTML <base>标记.它表示最终HTML输出中使用的所有相对URL的基本URL.

You need either to insert the context path to your webapp (e.g. /webapp/styles.css) or use a relative path or use the HTML <base> tag. It denotes the base URL of all relative URL's used in the final HTML output.

<head>
    <base href="${pageContext.request.contextPath}">
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <script type="text/javascript" src="js/script.js"></script>
</head>

这篇关于无法在JSP页面中加载外部CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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