Methods for illustrations in jsp pages: first create "Dynamic Web Project"; then create an image folder under WebContent and put pictures in; then write the picture path code in "index.jsp"; finally Just run the program to view the image in your browser.

Recently, I encountered a problem when I was new to Java Web, that is, images could not be displayed in jsp. I searched a lot of things on the Internet, and they basically talked about path problems, because I wrote
based on my little HTML experience at the beginning, and I thought it was impossible to write the wrong path, but Later it was discovered that there were indeed some problems with the path. (This shows that you should not trust your half-baked experience too much)
Recommended courses: Java Tutorial.
First of all, we need to re-understand relative paths and absolute paths.
Relative path: refers to the path relationship with other files (or folders) caused by the path where this file is located.
Absolute path: The full path provided to the file, including the applicable protocol or drive letter. That is, the real full path of the file or directory on your home page on the hard disk.
According to my search on the Internet, absolute paths cannot be used directly in jsp. (Need to configure tomcat)
So use relative paths, so your picture folder and your jsp file must be at the same level (that is, in the same directory), so that you can call it well .
My best practices for this issue are given below
Preparation part: Set up a Dynamic Web Project. (My project name here is Shop3)
Create an image folder under WebContent and put the image How to add illustrations in jsp page.

#Create the index.jsp file under WebContent.

Here we can see that the jsp file and index file are in the same directory.
Write the image path code in index.jsp.
<img src="/static/imghwm/default1.png" data-src="https://img.php.cn/upload/image/174/497/693/1557907571521925.png?x-oss-process=image/resize,p_40" class="lazy" to add illustrations in jsp page alt="How to add illustrations in jsp page" >
Run the program and you can see the picture displayed in the browser.

The above is the detailed content of How to add illustrations in jsp page. For more information, please follow other related articles on the PHP Chinese website!
How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?Mar 17, 2025 pm 05:46 PMThe article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.
How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management?Mar 17, 2025 pm 05:45 PMThe article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.
How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?Mar 17, 2025 pm 05:44 PMThe article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra
How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?Mar 17, 2025 pm 05:43 PMThe article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]
How does Java's classloading mechanism work, including different classloaders and their delegation models?Mar 17, 2025 pm 05:35 PMJava's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver CS6
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.






