1

I have problem with .css file on my JSP page.

My page looks like this:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

...
<link href="test.css" rel="stylesheet" type="text/css">
...

<body>

<div id="header">....

When I deploy my application on JBoss5.1 a get a warn message:

WARN [PageNotFound] No mapping found for HTTP request with URI [/appTest1-web/test.css] in DispatcherServlet with name 'appTest1'

Anybody know why?

ADDED

<?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_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>appTest1</display-name>


    <servlet>
        <servlet-name>appTest1</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appTest1</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>
            index.jsp
    </welcome-file>
    </welcome-file-list>

</web-app>

3 Answers 3

2

Is the base URL that you're using to call this page: /appTest1 by chance?

I assume you simply have placed this page/controller under /appTest1 and thus when it looks for any resource on the page (e.g. your css, any image, js's, etc) it is looking under "/appTest1/your_resource"

Perhaps the class that contains your controller has something like @RequestMapping("appTest1")? or perhaps that's a JBoss artifact (if so, I'm not a JBoss guy, so can't suggest ideas there).

In any case, your CSS file should probably be referenced appropriately with either "../test.css", or the static reference, such as: "/static/css/test.css", I choose the latter.

Incidentally, in spring I configured a static directory for non-dynamic content with:

<mvc:resources mapping="/public/**" location="/public/"/>

Large scale websites also consider putting static content under a separate domain such as static.mydomain.com or mycontentdomain.net to avoid having cookies passed along with static content.

Hope all that helps you get yourself pointed in the right direction.

Sign up to request clarification or add additional context in comments.

4 Comments

I added my web.xml to the question
Ok, I added <mvc:resources mapping="/public/**" location="/public/"/> and I was change <link href="test.css" rel="stylesheet" type="text/css"> to <link href="public/test.css" rel="stylesheet" type="text/css">The exception does not appear, but I do not see the jsp can not see the style: (
Can you open the css file in your browser? If yes, try to use the absolute path from your browsers address bar in the href element of the link.
Could you please explain a bit more, how you have solved the problem? where you placed the "public" folder, under the WEB-INF directory? I have the same problem, and I can't browse the css file from the address bar. Thanks.
0

Seems like your DispatcherServlet is trying to process the test.css. Check your web.xml to see if * or .css requests are directed to your DispatcherServlet. You should look for something like below. Make sure to limit the url-pattern to the extensions you want to be directed to the dispatcher servlet.

<servlet-mapping>
  <servlet>dispatcher</servlet>
  <url-pattern>/*</url-pattern>
</servlet-mapping>

Comments

0

I think you somewhere else in xml make mistake, but in more advanced redirection you can use UrlRewrite filter http://www.tuckey.org/urlrewrite/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.