I\'m having trouble with loading CSS and images and creating links to other pages when I have a servlet forward to a JSP. Specifically, when I set my
You can try out this one as well as. Because this worked for me and it's simple.
<style>
<%@ include file="/css/style.css" %>
</style>
You must analyse the actual HTML output, for the hint.
By giving the path like this means "from current location", on the other hand if you start with a /
that would mean "from the context".
If you are using Spring MVC, then you need to declare default action servlet for static contents. Add the following entries in spring-action-servlet.xml. It worked for me.
NOTE: keep all the static contents outside WEB-INF.
<!-- Enable annotation-based controllers using @Controller annotations -->
<bean id="annotationUrlMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="order" value="0" />
</bean>
<bean id="controllerClassNameHandlerMapping" class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping">
<property name="order" value="1" />
</bean>
<bean id="annotationMethodHandlerAdapter" class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
Your welcome page is set as That Servlet . So all css , images path should be given relative to that servlet DIR . which is a bad idea ! why do you need the servlet as a home page ? set .jsp as index page and redirect to any page from there ?
are you trying to populate any fields from db is that why you are using servlet ?
Below code worked for me.
instead of use <%@ include file="styles/default.css"%>
I faced similar issue with Spring MVC application. I used < mvc:resources >
tag to resolve this issue.
Please find the following link having more details.
http://www.mkyong.com/spring-mvc/spring-mvc-how-to-include-js-or-css-files-in-a-jsp-page/