-1

here is my problem: i'm trying to add a css style to my jsp file but it doesn't work at all. I have already tried a few recommended solutions, but none of them works.

index.jsp:

 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core_1_1" %>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>


<html>
    <head>
        <meta  http-equiv="CONTENT-TYPE" content="text/html;charset = UTF-9"/>
        <link rel="stylesheet" href="<c:url value="/WEB-INF/content/style.css"/>" type="text/css"/>
    </head>
  <body>
         <h2>What's ur name?</h2>

         <form method="post">
             <input type="hidden" name="submitted" value="true" />

         <input type="text" name="name" value="<c:out value="${param.name}"/>" />

             <input type="submit" value="submit" />

  </body>
</html>

style.css:

body
{
    color:lightgray;
}

Do u guys probably have any idea what's wrong with my code ?

Piotr
  • 87
  • 7
  • 1
    The app server **will not** allow clients to directly access content under WEB-INF. Move your static css to a publicly accessibly location. How are you building, packaging and deploying your application? – Elliott Frisch Apr 14 '16 at 13:43
  • This [answer](http://stackoverflow.com/a/14571407/873976) might help you – Sandeep Sukhija Apr 14 '16 at 13:47
  • @ElliottFrisch WebAppJSP-->src-->main-->webapp-->WEB-INF-->content-->style.css. Is there any way to paste a print screen here or copy the build tree? That would be helpful – Piotr Apr 14 '16 at 13:57
  • Move `WebAppJSP-->src-->main-->webapp-->WEB-INF-->content` to `WebAppJSP-->src-->main-->webapp-->content` and use `/content/style.css` in your `href`. Alternatively, serve your static resources from another URL (or a CDN). – Elliott Frisch Apr 14 '16 at 13:59
  • Is your WEB-INF inside WebContent folder? – Sandeep Sukhija Apr 14 '16 at 14:01
  • @ElliottFrisch that solution was correct. Thanks a lot! I can use this path with taglib c:url or without it, both methods are good. – Piotr Apr 14 '16 at 14:09

1 Answers1

0

On your href try using single quotes for the outer pair and double for the inner or viceversa

<link rel="stylesheet" href='<c:url value="/WEB-INF/content/style.css"/>' type="text/css"/>
Angelo Oparah
  • 673
  • 1
  • 7
  • 18