๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ๋ฐœ์–ธ์–ด/JSP

[JSP/Servlet] css, js ์ ์šฉ์ด ์•ˆ๋จ ํ•ด๊ฒฐํ•˜๊ธฐ

by yunamom 2022. 4. 5.
๋ฐ˜์‘ํ˜•

์•ˆ๋…•ํ•˜์„ธ์š” yunamom ์ž…๋‹ˆ๋‹ค :D

 

ํ”„๋กœ์ ํŠธ๋ฅผ ํ•˜๋‹ค๋ณด๋ฉด JSP ์— css, js ํŒŒ์ผ์ด ์ ์šฉ์ด ์•ˆ๋˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋Š”๋ฐ์š”

 

an error occurred trying to load the resource ์—๋Ÿฌ๊ฐ€ ๋‚˜๊ฒŒ๋ฉ๋‹ˆ๋‹ค.

 

 

์ด๋Ÿด๊ฒฝ์šฐ web.xml ์—์„œ mapping์„ ํ•ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.๐Ÿ˜Š

 

WEB-INF/web.xml 

web.xml ํŒŒ์ผ์ƒ์„ฑ

๐Ÿ‘‡ web.xml ์— ์•„๋ž˜์™€ ๊ฐ™์ด ์ž‘์„ฑํ•ด์ค๋‹ˆ๋‹ค.

<web-app>
	<servlet-mapping>
		<servlet-name>default</servlet-name>
		<url-pattern>*.js</url-pattern>
		<url-pattern>*.css</url-pattern>
		<url-pattern>*.jpg</url-pattern>
		<url-pattern>*.gif</url-pattern>
		<url-pattern>*.png</url-pattern>
		<url-pattern>*.ico</url-pattern>
		<url-pattern>*.swf</url-pattern>
	</servlet-mapping>

	<servlet-mapping>
		<servlet-name>jsp</servlet-name>
		<url-pattern>*.jsp</url-pattern>
		<url-pattern>*.jspx</url-pattern>
	</servlet-mapping>
</web-app>

before
after

๐Ÿ’ก๋งŒ์•ฝ ์›น ์บ์‹ฑ ๋•Œ๋ฌธ์— ์ด์ „ css๊ฐ€ ์ ์šฉ๋˜๋Š” ๊ฒฝ์šฐ์—๋Š” ๋์— ๋ฒ„์ „์„ ์ถ”๊ฐ€ํ•ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. (ver=1)

<link rel="stylesheet" type="text/css" 
href="${pageContext.request.contextPath}/css/style.css?ver=1">

 

300x250

์ฝ”๋“œ