How to add static resources in Spring MVC Java Images CSS
Note: We are going to do following things.
- Add the resource mapping
- Create a new directory css
- Add a new style.css file
- Create a new directory img
- Add a new image
- Create a new directory script
- Add a new file myscript.js
- 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
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 Image file.