2013-08-24 1 views
0

tomcat 7.0을 사용하고 있습니다. 이제는 CSS 및 js 파일을로드 할 수없는 문제가 있습니다. $ {pageContext.request.contextPath}를 추가하려고했지만 작동하지 않습니다. 또한 c : url 태그를 시도했지만 eclipse에서 구문 오류가 발생했습니다.

이러한 파일 구조는 다음

의 WebContent
-content/CSS/lab3.css
HTML과 JS 폴더 여기서도

<?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> 

콘텐츠 폴더하에되는 HTML 헤드 :

<link rel="stylesheet" type= "text/css" href= "${pageContext.request.contextPath}/css/lab3.css" media="screen, projection"> 
+0

식 '$ {pageContext.request.contextPath} '와 같은 것은 일반 HTML 파일에서 사용할 수 없으므로 JSP 파일 내에서 사용해야합니다. 먼저 자바 서블릿과 JSP에 대한 자습서를 읽어 보는 것이 좋습니다. –

+0

@DavidLevesque 그래, 일반 HTML 파일에서 어떻게 위치에 액세스해야합니까? – Chwa

+0

상대 경로를 사용할 수 있습니다. 예 :'href = "../ css/lab3.css" ' –

답변

6

EL expressions ${} 일반 HTML 파일에서 실행되지 않습니다. 이자형. 그것은 JSP (및 Facelets) 파일에서만 실행됩니다. 특정 경우, lab3.jsplab3.html 이름을 변경하거나 web.xml에 다음 JSP 서블릿 매핑을 추가 단지 문제가 될 것입니다 : 그들은 JSP 파일이있는 것처럼 모든 .html 파일을 치료하기 위해 Tomcat을 말할 것이다

<servlet-mapping> 
    <servlet-name>jsp</servlet-name> <!-- This is the default servlet name of Tomcat's own JSP servlet. To be sure, look in Tomcat's own web.xml for the exact name. --> 
    <url-pattern>*.html</url-pattern> 
</servlet-mapping> 

결과적으로 EL은 .html 파일에서도 즉시 작동합니다.

위의 방법 중 하나라도 만족스러운 해결 방법이 없다면 논리적 사고로 회귀하고 상대 경로를 올바르게 이해하고 사용해야합니다. 로컬 디스크 파일 시스템에서와 마찬가지로 ../은 하나의 폴더를 URL에 표시합니다. HTML 파일이 /content/html/lab3.html에 있고 CSS 파일이 /content/css/lab3.css에 있는지, 다음은 어떻게해야 제공 :

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

사용 $ {request.contextPath} 대신 $의 {pageContext.request.contextPath}

+0

안녕하세요, 어떻게 작동하는지 설명해주세요. –

관련 문제