Home
Videos
Spring Videos
How to add static resources in Spring MVC Java Images CSS

How to add static resources in Spring MVC Java Images CSS

Description

It is a descriptive videos tutorial for using static resources like Images, CSS and Javascript in Spring mvc. If you need source code or program of this video tutorial, please write down your email address in comments so that I may send you code

Static Resources in Spring MVC Java Images CSS and JavaScript

Let's add Static resources like CSS, Images, and JavaScript in our previous spring project. You need to add some additional things for importing JavaScript file in view.

Note: We are going to do following things.

  1. Add the resource mapping
  2. Create a new directory css
  3. Add a new style.css file
  4. Create a new directory img
  5. Add a new image
  6. Create a new directory script
  7. Add a new file myscript.js
  8. update users.jsp view.


Step 1: Add the resource mapping

Note: Add code for mapping resource directory in applicationContext.xml


Step 2: Create a new directory "css"

Note: Create a new css folder in webapp/resources/ directory.


Step 3: Add a new CSS file

Note: Add new css file named style.css in webapp/resources/css directory


Step 4: Create a new directory "img"

Note: Create a new img folder in webapp/resources/img directory.


Step 5: Add a new image file

Note: Copy following image file and add to webapp/resources/img

SindhiTutorials

Step 6: Create a new directory "script"

Note: Create a new script folder in webapp/resources/ directory


Step 7: Add a new script file.

Note: Add a new script file named myscript.js in webapp/resources/script. I have moved script from view to this file.


Step 8: Update existing view

  • Add code for tag library.
  • Add code for importing css file.
  • Add code for importing JavaScript file.
  • Add code for importing Image file.


If you need help for your project to use static resources like css file, javascript file and image in spring mvc, please comment blow so that We may reply you asap