How to add CSS and JS to Spring mvc project
Move the resource
folder under webapp
folder. And with this line you can connect your css file.
<link rel="stylesheet" href="/css/styles.css">
Similarly write code to connect script like
<script type="text/javascript" src="/js/script.js"></script>
How to include js and CSS in JSP with spring MVC
First you need to declare your resources in dispatcher-servlet file like this :
<mvc:resources mapping="/resources/**" location="/resources/folder/" />
Any request with url mapping /resources/** will directly look for /resources/folder/.
Now in jsp file you need to include your css file like this :
<link href="<c:url value="/resources/css/main.css" />" rel="stylesheet">
Similarly you can include js files.
Hope this solves your problem.
cannot load css and js files when using spring mvc
Try any of the below :
With JSTL tag c:url
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<link href="<c:url value="/design/css/reset.css" />" rel="stylesheet">
With spring:url
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<spring:url value="/design/css/reset.css" var="reset" />
without any tags
<link href="${pageContext.request.contextPath}/design/css/reset.css" rel="stylesheet"
Related Topics
Text-Align: Center Placeholder Text in Select
Position Div Box at The End of After Ensuing Elements
Why Are These Two Inline-Blocks Not Aligned
Issue on Ie7 When Page Is Scrolling.Text Is Not Proper
How to Get Overlapping Divs with Relative Positions
Simulating Position: Fixed in Ie6 with a Div of 100% Height
How to Use Image as a Table Background in Email
How to Hide Any Text from Sighted User and Search Engine But Not from Screen Reader
CSS: Placing Divs Left/Center/Right Inside Header
HTML5 & Bootstrap Class="Container", Can It Be Applied to Body or Only Div
How to Make a Div Fill The Remaning Vertical Space Using CSS
What's The Most Efficient and Reliable Method to Test CSS Design in Multiple Legacy Browsers
How to Add Horizontal Padding to Every Line in One Multi-Line Wrapped Sentence
CSS: Wrong Position of "Transform: Scale();" Container Children