1

I have visited previous related question to find solution but I didn't...

How to use "css" in the "jsp" in Spring MVC project?

including style sheet in a jsp page with Spring MVC

My question is how do I link css file to .jsp file in Spring MVC, this question was asked by so many of em! but unfortunately couldn't get achieved with those solution.

file structure is- https://i.stack.imgur.com/9WKuN.png

Please give your directions, thanks.

Community
  • 1
  • 1
Java.beginner
  • 871
  • 2
  • 19
  • 37

2 Answers2

3

I was able to achieve that with the following

<style type="text/css"><%@ include file="/css/bootstrap.css" %> </style>

where bootstrap.css was my css file and the folder structure was similar. Try that once.

Java.beginner
  • 871
  • 2
  • 19
  • 37
nagamanojv
  • 301
  • 5
  • 16
  • You mean like this... – Java.beginner Oct 08 '14 at 09:59
  • Yes. The css file path you mention in file=... is relative to your WebContent directory. Since you have "css" directory directly under WebContent, the above should be sufficient. – nagamanojv Oct 08 '14 at 10:04
  • Thanks @nagamanojv, when I did -- server throws an error -- message /WEB-INF/AdmissionForm.jsp (line: 10, column: 27) Invalid directive, I don't know where I am going wrong, thanks for your help – Java.beginner Oct 08 '14 at 10:10
  • Its not .. It is . The server was throwing error because @file is not a valid directive. Please try the one I mentioned. (There should be a space between @ and include. Please mind that) – nagamanojv Oct 08 '14 at 10:13
  • When I do like this, -- error on the line and when hover on x mark shows -- Fragment "bootstrap.css" was not found at expected path /FirstSpringMVCProject/WebContent/WEB-INF/ bootstrap.css – Java.beginner Oct 08 '14 at 10:20
  • thanks, you are diamond, it worked by doing like this -- , thanks for your help, much appreciated!!! – Java.beginner Oct 08 '14 at 10:24
  • could you please look into the question below, now I can't link .js files, please have a look, thanks... http://stackoverflow.com/questions/26336029/link-jquery-file-with-spring-mvc – Java.beginner Oct 13 '14 at 12:27
  • @Java.beginner: I proposed a solution for your problem in the specified link. Please check that. – nagamanojv Oct 14 '14 at 04:29
1

add following line in your spring-dispatcher-servlet.xml

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

hope this will help you

Saurabh Gaur
  • 23,507
  • 10
  • 54
  • 73