2012-11-08 146 views
1

我想將我在eclipse中創建的css鏈接到jsp,並且當我運行該項目時,我在瀏覽器中得不到任何結果。我已經嘗試了多種方式,通過投入將eclipse中內置的CSS鏈接到jsp並獲取結果

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

<link rel="stylesheet" href="boe/WebContent/first.css" type="text/css"> 

<link rel="stylesheet" href="(my full path to the file)" type="text/css"> 

我已經試過這麼多,我不記得我是如何得到它沒有錯誤。我得到這個

Tag (link) should be an empty-element tag. 

作爲警告錯誤。

我無法找到任何步驟創建css並使其鏈接到jsp,所以它可以顯示在我的瀏覽器。

這裏是我的代碼爲jsp和css。

的jsp:

<?xml version="1.0" encoding="UTF-8" ?> 
<%@ page import="java.util.*" language="java" contentType="text/html; charset=UTF-8" 
pageEncoding="UTF-8"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <link rel="stylesheet" href="css/first.css" type="text/css"> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    <title>TestPage - Test1</title> 
</head> 

<body> 
    <div id="page-container">Hello World</div> 
    <%Date d = new Date(session.getLastAccessedTime());%> 
    this page was last viewed <%= d.toString() %> 
</body> 
</html> 

CSS:

@CHARSET "UTF-8"; 
html, body { 
    margin:0; 
    padding:0; 
} 

#page-container { 
    width: 760px; 
    margin: auto; 
    background: red; 
} 

上發現一步步或者如果你有一個很好的解釋,這將是非常讚賞的任何幫助。謝謝

回答

7

標記(鏈接)應該是一個空元素標記。

此錯誤消息告訴你,你link標籤需要一個結束斜槓:

<link rel="stylesheet" href="css/first.css" type="text/css" /> <-- see the closing '/' 

如果不解決這個問題,我的猜測是,你的道路是不完全正確。

+0

謝謝你。它將錯誤消除了,但仍然沒有得到css實現的結果。 –

0

我在

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

<head> 
    <style type="text/css"> 
    <%@include file="css/first.css" %></style> 
</head> 

,並在「的WebContent」文件在我的Eclipse項目資源管理器中改變了我添加了一個名爲「CSS」的文件夾,並first.css移動到夾。

雖然從我讀到的,這是一個非常低效的方式鏈接它,因爲它導入整個CSS。

+0

你不需要整個CSS嗎?這實際上會更高效,因爲它減少了加載頁面及其資源所需的請求數量。 –

0

在上面的代碼替換「CSS」與CSS文件 的完整路徑ü可以通過在.css文件點擊右鍵得到完整的路徑 - >屬性 - >位置 複製和粘貼在上面的代碼'css'的地方