0

I have been trying to get my '.jsp' file to use a '.css' file that I have created. I had originally stored the '.css' file in my 'WEB-INF' folder but through some searching found that the 'WEB-INF' folder is not public and can therefore not store the file so I moved it outside into the 'webapp' folder but I am still not getting anywhere.

The files 'index.jsp' and 'index.css' files are in the same folder:

'HelloWord/src/main/webapp'

My '/jsp' file links the '.css' as shown

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" href="${pageContext.request.contextPath}/index.css" type="text/css" /> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>MM Vehicle Registration</title>
</head>

I get the following error when I try to run:

Nov 28, 2015 3:42:00 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/HelloWorld/index.css] in DispatcherServlet with name 'dispatcher'

The web page still displays ony without the css decoration. The file is already declared in a '.jsp' that is being rendered fine so why would I receiving this error?

algorhythm
  • 3,304
  • 6
  • 36
  • 56

2 Answers2

0

try replace

'${pageContext.request.contextPath}/index.css' 

with

'/index.css'.

Are both index.css and index.jsp in the root folder of webapp? Ok,the strutre is right.Now I suggest you to check you web.xml. You might have something like this?

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

Try calling your controllers with a different extension (.do for example) and update the servlet-mapping to suit

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

then try to access to /helloworld/index.css.if ok,rollback '/index.css'. to '${pageContext.request.contextPath}/index.css'

John.Doe
  • 1
  • 3
  • I had already tried that but it didn't work. Their paths are 'HelloWord/src/main/webapp/index.jsp' and 'HelloWord/src/main/webapp/index.css' – algorhythm Nov 28 '15 at 16:32
  • Is your project a maven web project?please show me the full project strutre. – John.Doe Nov 28 '15 at 17:22
0

Spring takes control over all URLs. You need to put <mvc:resources> into your configurtion and preferably put your client resources into WEB-INF/resources/ directory. Also check How to handle static content in Spring MVC?

Community
  • 1
  • 1
Zbynek Vyskovsky - kvr000
  • 18,186
  • 3
  • 35
  • 43