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 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!