Referencing CSS in jsp through $ pagecontext.request.contextpath in tomcat8 does not work

1

I'm using tomcat 8. My css and js files do not load into jsp through the $ pagecontext.request.contextpath in tomcat8. I can only load the css if I put the absolute path from the webapp directory. Ex (pages / css / style.css).

The project structure is as follows:

src
webapp
pages
css
js

Note: My jsp files are in the same hierarchy as the js and css folders.

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
    <display-name>Yellow Pages</display-name>
    <welcome-file-list>
        <welcome-file>paginas/index.jsp</welcome-file>
    </welcome-file-list> ...

The Head of jsp:

<link  type="text/css" href="${request.contextPath}css/bootstrap.min.css" rel="stylesheet">
<link  type="text/css" href="${request.contextPath}css/bootstrap-theme.min.css" rel="stylesheet">

Any help is welcome, thanks!

    
asked by anonymous 24.07.2015 / 02:06

2 answers

2

The following jsp configuration in web.xml was wrong:

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >

After much searching, I encountered someone with the same problem on this link >, I noticed that the specified version of JSP did not support Expression Language.

I've inserted the following most up-to-date specification and succeeded:

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
     http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0"
    >
    
29.07.2015 / 02:32
3

Tried to use it as follows?

<link rel="stylesheet" 
href="${pageContext.request.contextPath}/css/estilo.css" type="text/css"/>

If this does not work try putting the $ {pageContext.request.contextPath} value inside an input to find out what value it stores:

<input value="${pageContext.request.contextPath}">
    
24.07.2015 / 04:41