Skip to content

Instantly share code, notes, and snippets.

@darbyluv2code
Last active December 24, 2022 14:52
Show Gist options
  • Save darbyluv2code/9a09543a226baeedc04b9a5037ca52ec to your computer and use it in GitHub Desktop.
Save darbyluv2code/9a09543a226baeedc04b9a5037ca52ec to your computer and use it in GitHub Desktop.
Spring MVC - Reading CSS, JavaScript and Images
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/resources/css/my-test.css">
<script src="${pageContext.request.contextPath}/resources/js/simple-test.js"></script>
</head>
<body>
<h2>Spring MVC Demo - Home Page</h2>
<a href="showForm">Plain Hello World</a>
<br><br>
<img src="${pageContext.request.contextPath}/resources/images/spring-logo.png" />
<br><br>
<input type="button" onclick="doSomeWork()" value="Click Me"/>
</body>
</html>
body {
background-color: lightblue;
}
h2 {
color: white;
text-align: center;
}
p {
font-family: verdana;
font-size: 20px;
}
function doSomeWork() {
alert("I'm doing some work!!!");
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- Step 3: Add support for component scanning -->
<context:component-scan base-package="com.luv2code.springdemo" />
<!-- Step 4: Add support for conversion, formatting and validation support -->
<mvc:annotation-driven/>
<!-- Step 5: Define Spring MVC view resolver -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
<mvc:resources mapping="/resources/**" location="/resources/" />
</beans>
@DanieleIuliano
Copy link

org.springframework.web.servlet.PageNotFound.noHandlerFound No mapping for GET i have this error for the request of images and javascript

@navnit75
Copy link

Beauty.

@HuzaifaBinZahoor
Copy link

HuzaifaBinZahoor commented Dec 31, 2021

This course and learning are giving so much confidence in development. The way you are explaining and elaborating concepts with practical is so much productive.
Thanks, Chad

@mkmadhan1990
Copy link

My project is not working.both css and javascript are not running from html page.please help

@darbyluv2code
Copy link
Author

darbyluv2code commented Feb 13, 2022

@mkmadhan1990 - Can you repost the question to the Udemy classroom discussion Q&A? We'll help you there.
Here's the link to the classroom discussion Q&A:
https://www.udemy.com/spring-hibernate-tutorial/learn/v4/questions

@dhanuka0827
Copy link

Hi Chad! 20% through the course, and I want to thank you already. My concept around Spring were never so clear. Thank you again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment