Directly access files (pictures, etc.) through tomcat (http://localhost:8080/)

 


 
 

  

Add configuration to Tomcat

Add configuration as follows:

<Context path="/image" docBase="H:/online/picture" reloadable="true" crossContext="true"></Context>

The attributes of the Context tag are:

  • path : Specify the URL entry to access the web application, which is the access path through http://localhost:8080/ path .
  • docBase : Specify the file path of the web application, either an absolute path or a relative path relative to the appBase attribute of <Host>, if the web application adopts an open directory structure, specify the root directory of the web application, if the web application If it is a war file, specify the path of the war file. (Specify the address of the project)
  • reloadable : If this attribute is set to true , the tomcat server will monitor the changes of the class files in the WEB-INF/classes and WEB-INF/lib directories when it is running. If it detects that a class file has been updated, the server will automatically reload Load the web application.
  • crossContext : If you want to call ServletContext.getContext() in the application to return the request dispatcher of other web applications running on the virtual host, set it to true. In environments where security is important, set to false to cause getContext() to always return null. The default value is false.

Place the Context tag in the <Host> tag of Tomcat's conf/server.xml.
Context placement
Then save and restart Tomcat for the configuration to take effect.

 
 

 
 

 
 

access

Start Tomcat directly

In the .\apache-tomcat-9.0.35\bin directory, double-click startup.bat to open the window, and double-click shutdown.bat to close the window.
picture
Via the URL: http://localhost:8080/image/1.jpg browser access is successful.
Access successful

 
 

 
 

 
 

Start Tomcat through IDEA

IDEA checks in Tomcat's settings

  • Deploy applications configured in Tomcat instance。

IDEA settings
Then you can access it just like starting Tomcat directly.

Guess you like

Origin blog.csdn.net/qq_43448856/article/details/123234632