eclipse 将eclipse中内置的css链接到jsp并获得结果

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13293235/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 19:22:01  来源:igfitidea点击:

Linking css built in eclipse to jsp and getting results

csseclipsejsp

提问by Trae Moore

I am trying to link a css i created in eclipse to the jsp and when i run the project i get no results in my browser. I've tried it in multiple ways, by putting

我试图将我在 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">

I've tried so much that i don't remember how i got it to not error out. i am getting this

我已经尝试了很多,以至于我不记得我是如何让它不出错的。我得到这个

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

as the caution error.

作为警告错误。

i can not find any step by steps on creating the css and making it link to the jsp, so it can show up in my browser.

我找不到关于创建 css 并将其链接到 jsp 的任何步骤,因此它可以显示在我的浏览器中。

here is my code for both the jsp and the css.

这是我的jsp和css代码。

jsp:

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:

css:

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

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

any help on finding a step by step or if you have a good explanation, it would be much appreciated. Thank you

任何有关一步一步寻找的帮助,或者如果您有一个很好的解释,我们将不胜感激。谢谢

回答by Kevin Boucher

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

标签(链接)应该是一个空元素标签。

This error message is telling you that your linktag needs a closing slash:

此错误消息告诉您您的link标签需要一个结束斜线:

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

If that doesn't fix it, my guess is that your path is not quite right.

如果这不能解决问题,我的猜测是您的路径不太正确。

回答by Trae Moore

I changed in the

我在

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

to

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

and in my eclipse project explorer under the "WebContent" file i added a folder named "CSS" and moved first.css to that folder.

在我的 Eclipse 项目资源管理器中的“WebContent”文件下,我添加了一个名为“CSS”的文件夹并将 first.css 移动到该文件夹​​中。

Although from what i read, this is a very inefficient way of linking it because it imports the entire css.

尽管从我读到的内容来看,这是一种非常低效的链接方式,因为它会导入整个 css。

回答by ajay

In the above code replace 'css' with the full path of the css file u can get the full path by right click on .css file -> properties->location copy that and paste in above code in place of 'css'

在上面的代码中,将“css”替换为 css 文件的完整路径,您可以通过右键单击 .css 文件 -> 属性 -> 位置复制并粘贴上面的代码来代替“css”来获取完整路径