我不能 link 我的 css 到我的 jsp 在 eclipse 上处理动态 web 项目 jee
i can't link my css to my jsp in eclipse working on dynamic web project jee
大家好,我想 link 我的 css 文件到我的 jsp 。
我的 css 文件位于 WebContent 中名为 css 的文件夹中。
我的 css 文件的路径:/PFE/WebContent/css/styleLogin.css
<head>
<title>Login Page</title>
<link rel="stylesheet" href="css/styleLogin.css" />
</head>
我尝试了不同的路径,例如:
<link rel="stylesheet" href="../css/styleLogin.css" />
<link rel="stylesheet" href="WebContent/css/styleLogin.css" />
/PFE/WebContent/css/styleLogin.css
我不想使用内部 css,即使它可以工作。
当我创建 css 文件时出现错误:找不到 node.js。这将导致编辑器缺少关键功能。
更新:
我试过
href="${pageContext.request.contextPath}/css/styleLogin.css" />
<link rel="stylesheet" href="/PFE/css/styleLogin.css" /> <--% PFE=nameOfProject --%>
但它不起作用我用 :
测试了路径
<style type="text/css">
<%@include file="/css/styleLogin.css" %>
</style>
我现在确定路径了,因为我使用此语法没有错误,但我仍然看不到我的 css 工作。
目前唯一的解决办法**
我只能使用没有 include 的 internal css 并且它工作正常但仍然不是最佳的。
**更新 2:
我创建了一个简单的测试 Web 动态应用程序:
在 WEB-INF 中:我有 index.jsp && web.xml
在 WebContent:i 中有一个名为 css 的文件夹,其中 css 文件名为 styleIndex
路径
"css/styleIndex.css"
in src : 一个包 'pack.servlet' 一个名为 Index.java
的 servlet
web.xml的源代码:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>test</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>index</servlet-name>
<servlet-class>pack.servlet.Index</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>index</servlet-name>
<url-pattern>/index</url-pattern>
</servlet-mapping>
</web-app>
index.java的源代码:
包裹 pack.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/Index")
public class Index extends HttpServlet {
private static final long serialVersionUID = 1L;
public Index() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
this.getServletContext().getRequestDispatcher("/WEB-INF/index.jsp");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
index.jsp的代码来源:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Index page </title>
<link rel="stylesheet" href="/test/css/styleIndex.css" />
</head>
<body>
<p>Hello World ... </p>
</body>
</html>
styleIndex.css的代码来源:
body {
background-color: lightblue;
}
p{
color:bleu;
}
当我在我的服务器 Apache Tomcatv7.0 上执行它时,我收到一条错误消息:
Staring Tomcat v7.0 服务器在 localhost 遇到问题。
在详细信息中:
服务器 Tomcat v7.0 位于本地主机的服务器无法启动。
我的另一个项目 运行 使用同一台服务器没问题。
尝试使用:
<link rel="stylesheet" type="text/css" href="/YOUR_APP_NAME/css/styleLogin.css" />
伙计们,我刚刚使用 jdk 8 重新安装了 Eclipse,然后我将 css 放在 WebContent 中名为 css 的文件夹中。
最后将我的 jsp 链接到 :
<link rel="stylesheet" href="<c:url value ="/css/loginStyle.css"/>" />
您将 css 文件保存在 WebContent 文件夹中,只需在 jsp 中添加以下行即可引用它。
大家好,我想 link 我的 css 文件到我的 jsp 。 我的 css 文件位于 WebContent 中名为 css 的文件夹中。 我的 css 文件的路径:/PFE/WebContent/css/styleLogin.css
<head>
<title>Login Page</title>
<link rel="stylesheet" href="css/styleLogin.css" />
</head>
我尝试了不同的路径,例如:
<link rel="stylesheet" href="../css/styleLogin.css" />
<link rel="stylesheet" href="WebContent/css/styleLogin.css" />
/PFE/WebContent/css/styleLogin.css
我不想使用内部 css,即使它可以工作。 当我创建 css 文件时出现错误:找不到 node.js。这将导致编辑器缺少关键功能。
更新: 我试过
href="${pageContext.request.contextPath}/css/styleLogin.css" />
<link rel="stylesheet" href="/PFE/css/styleLogin.css" /> <--% PFE=nameOfProject --%>
但它不起作用我用 :
测试了路径<style type="text/css">
<%@include file="/css/styleLogin.css" %>
</style>
我现在确定路径了,因为我使用此语法没有错误,但我仍然看不到我的 css 工作。 目前唯一的解决办法** 我只能使用没有 include 的 internal css 并且它工作正常但仍然不是最佳的。 **更新 2: 我创建了一个简单的测试 Web 动态应用程序: 在 WEB-INF 中:我有 index.jsp && web.xml 在 WebContent:i 中有一个名为 css 的文件夹,其中 css 文件名为 styleIndex 路径
"css/styleIndex.css"
in src : 一个包 'pack.servlet' 一个名为 Index.java
的 servletweb.xml的源代码:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>test</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>index</servlet-name>
<servlet-class>pack.servlet.Index</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>index</servlet-name>
<url-pattern>/index</url-pattern>
</servlet-mapping>
</web-app>
index.java的源代码: 包裹 pack.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/Index")
public class Index extends HttpServlet {
private static final long serialVersionUID = 1L;
public Index() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
this.getServletContext().getRequestDispatcher("/WEB-INF/index.jsp");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
index.jsp的代码来源:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Index page </title>
<link rel="stylesheet" href="/test/css/styleIndex.css" />
</head>
<body>
<p>Hello World ... </p>
</body>
</html>
styleIndex.css的代码来源:
body {
background-color: lightblue;
}
p{
color:bleu;
}
当我在我的服务器 Apache Tomcatv7.0 上执行它时,我收到一条错误消息: Staring Tomcat v7.0 服务器在 localhost 遇到问题。 在详细信息中: 服务器 Tomcat v7.0 位于本地主机的服务器无法启动。 我的另一个项目 运行 使用同一台服务器没问题。
尝试使用:
<link rel="stylesheet" type="text/css" href="/YOUR_APP_NAME/css/styleLogin.css" />
伙计们,我刚刚使用 jdk 8 重新安装了 Eclipse,然后我将 css 放在 WebContent 中名为 css 的文件夹中。 最后将我的 jsp 链接到 :
<link rel="stylesheet" href="<c:url value ="/css/loginStyle.css"/>" />
您将 css 文件保存在 WebContent 文件夹中,只需在 jsp 中添加以下行即可引用它。