Thursday 15 August 2013

java - How does tomcat resolve resources? -



java - How does tomcat resolve resources? -

i develop web application.

spring+hibernate on tomcat servlet container.

today on pc deploy application , see css doesn't load.

in jsp utilize relative paths this(example)

<link href="/resources/css/ui-lightness/jquery-ui-1.10.0.custom.min.css" rel="stylesheet">

respective request browser sends:

http://localhost:8080/resources/css/ui-lightness/jquery-ui-1.10.0.custom.min.css

and request returns 404 http error.

for jsp:

<link href="/resources/css/bootstrap.min.css" rel="stylesheet">

browser sends:

http://localhost:8080/terminal-company/resources/css/bootstrap.min.css

thus can see first jsp project name doesn't add together url

why? , how prepare it? request me detail should add together relevant answer.

project structure:

spring related part of web.xml:

<servlet> <servlet-name>appservlet</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name>contextconfiglocation</param-name> <param-value>/web-inf/spring/webcontext.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>appservlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>

if goal able utilize absolute paths, without caring (and knowing) context path of webapp (/terminal-company in sec example), utilize the jstl <c:url> tag generate urls:

<link href="<c:url value='/resources/css/bootstrap.min.css'/>" rel="stylesheet">

the sec illustration send request /resources/css/bootstrap.min.css, , not /terminal-company/resources/css/bootstrap.min.css, unless there <base> tag in generated html page.

edit: original question didn't using spring, , mapped / dispatcher servlet. spring in charge of service resources. the documentation explains how configure it. doesn't alter above answer: independant of context path, utilize c:url.

java jsp tomcat servlets

No comments:

Post a Comment