tomcat - ${pageContext.request.contextPath} is not working on plain HTML -


i'm using tomcat 7.0. facing issue not load css , js file. trying add ${pagecontext.request.contextpath} not work, tried c:url tag, getting syntax error in eclipse.

the structure of these files is:

webcontent
-content/css/lab3.css
html , js folder under content folder well

<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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>lab3</display-name>   <welcome-file-list>     <welcome-file>/content/html/lab3.html</welcome-file>   </welcome-file-list> </web-app> 

here html head:

<link rel="stylesheet" type= "text/css" href= "${pagecontext.request.contextpath}/css/lab3.css"  media="screen, projection"> 

el expressions ${} doesn't run in plain html file. runs in jsp (and facelets) files only. in particular case, it'd merely matter of renaming lab3.html lab3.jsp, or adding following jsp servlet mapping web.xml:

<servlet-mapping>     <servlet-name>jsp</servlet-name> <!-- default servlet name of tomcat's own jsp servlet. sure, in tomcat's own web.xml exact name. -->     <url-pattern>*.html</url-pattern> </servlet-mapping> 

which tell tomcat treat .html files if jsp files, consequence el instantly work in .html files.

if none of above acceptable solution, you'd need fall logical thinking , understanding , using relative paths. in local disk file systems, ../ brings 1 folder in urls. provided html file in /content/html/lab3.html , css file in /content/css/lab3.css, following should do:

<link ... href="../css/lab3.css" /> 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -