0

I'm using Spring MVC with JBoss AS 7.1.1 Final.

My project is organized as follows:

Web Pages
|-- WEB-INF
|   |--jsp
|   |  |-- index.jsp
|   |-- applicationContext.xml
|   |-- dispatcher-servlet.xml
|   |-- jboss-web.xml
|   |-- web.xml
|-- resources
|   |-- css
|       |-- layout.css
|-- redirect.jsp

The file web.xml is:

<?xml version="1.0" encoding="UTF-8"?>
    <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/applicationContext.xml</param-value>
        </context-param>
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
        <servlet>
            <servlet-name>dispatcher</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>2</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>dispatcher</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
        <session-config>
            <session-timeout>
                30
            </session-timeout>
        </session-config>
        <welcome-file-list>
            <welcome-file>redirect.jsp</welcome-file>
        </welcome-file-list>
    </web-app>

The file jboss-web.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
    <context-root>/GUI</context-root>
</jboss-web>

The file redirect.jsp is:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<% response.sendRedirect("index.htm"); %>

How can I set up inside index.jsp a link to resources/css/layout.css?

vdenotaris
  • 13,297
  • 26
  • 81
  • 132

1 Answers1

1

Maybe I'm misunderstanding your question, but a link to a .css resource is as simple as

<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/resource/css/layout.css">

as long as you have EL enabled.

You'll also have to map your DispatcherServlet to something more restrictive like

/mvc/*

Alternatively, you can map such static content through Spring resource handler as described here.

Community
  • 1
  • 1
Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
  • You shouldn't need to map the servlet to "/mvc/*", but JBoss AS 7.1 seems to have an issue with "/" (it doesn't let an application override that mapping from Java config). Tomcat, Jetty, JBoss EAP 6.2, AS 8, all seem fine to me. – Dave Syer Feb 12 '14 at 14:53