Issue
Hey guys i want to link my css file to my jsp . my css file located in WebContent in a folder named css. the path of my css file: /PFE/WebContent/css/styleLogin.css
<head>
<title>Login Page</title>
<link rel="stylesheet" href="css/styleLogin.css" />
</head>
i tried differents paths like :
<link rel="stylesheet" href="../css/styleLogin.css" />
<link rel="stylesheet" href="WebContent/css/styleLogin.css" />
/PFE/WebContent/css/styleLogin.css
i don't want to use Internal css even if it's working . when i created my css file i got an error: could not find node.js. this will result in editors missing key features.
UPDATE: i tried
href="${pageContext.request.contextPath}/css/styleLogin.css" />
<link rel="stylesheet" href="/PFE/css/styleLogin.css" /> <--% PFE=nameOfProject --%>
but it's not working i tested the path with :
<style type="text/css">
<%@include file="/css/styleLogin.css" %>
</style>
i'm sure of the path now cuz i got no error with this syntax but still i can't see my css working . The only solution for now ** i can only use internal css with no include and that's it's working fine but still not optimal . **Update 2 : i created a simple test Web Dynamic app: in WEB-INF:i have index.jsp && web.xml in WebContent:i have a folder named css inside it css file named styleIndex the path
"css/styleIndex.css"
in src : a package 'pack.servlet' a servlet named Index.java
source code of 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>
source code of index.java: package 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 {
}
}
code source of 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>
code source of styleIndex.css :
body {
background-color: lightblue;
}
p{
color:bleu;
}
when i execute it on my server Apache Tomcatv7.0 i got an error msg : Staring Tomcat v7.0 Server at localhost has encountered a problem . in Details: Server Tomcat v7.0 Server at localhost failed to start. my other project running fine with the same Server .
Solution
Guys i just reinstalled Eclipse using jdk 8 then i placed my css in a folder named css inside WebContent . and finally linked my jsp with :
<link rel="stylesheet" href="<c:url value ="/css/loginStyle.css"/>" />
Answered By - AitSiBaha