MinionKing
MinionKing

Reputation: 187

can't access to my css file in my jsp

i have some issue accessing my CSS file. I did search, but i can't figure out what's incorrect.

web.xml :

 <servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>*.mvc</url-pattern>
</servlet-mapping>

my JSP :

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Portail web </title>
<link rel="stylesheet" type="text/css"
href="../GN/css/portail.css" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
 <h1>TEST</h1>
</body>
<html>

my css :

@CHARSET "ISO-8859-1";
body
{
background-color:blue;
}

My architecture :

JSP is at : webapp/WEB-INF/FR/JSP/portail.jsp

CSS is at : webapp/WEB-INF/GN/css/portail.css

I tried absolute path too, but nothing work (no style applied on my JSP).

Thanks.

EDIT :

If i do <%@ include file="/WEB-INF/GN/css/portail.css"%> it prints out my css, so the path is good but the style does not apply to my jsp :/

Upvotes: 1

Views: 2178

Answers (2)

rahul maindargi
rahul maindargi

Reputation: 5655

It's the web browser that is requesting the files from the web server. Your pages aren't directly accessing the files at all. All the files inside WEB-INF/ are not publicly accessible.

You have two possible solutions:

  1. Move .js and .CSS files outside of WEB-INF/

  2. Or use the following mapping:

    web.xml (Spring 3.0.3+)

<servlet>
  <servlet-name>default</servlet-name>
  <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
  <init-param>
    <param-name>debug</param-name>
    <param-value>0</param-value>
  </init-param>
  <init-param>
    <param-name>listings</param-name>
    <param-value>false</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
  <servlet-name>default</servlet-name>
  <url-pattern>/static/*</url-pattern>
</servlet-mapping>

In JSP use path /static/js/, /static/css/ etc.

Upvotes: 3

gma
gma

Reputation: 2563

../GN/css/portail.css point to FR/GN/css/portail.css and not to GN/css/portail.css

Try with ../../GN/css/portail.css

(If you are accessing your jsp directly but maybe is it forwarded from an action with a different url)

Upvotes: 0

Related Questions