Solve the problem of IDEA configuring Tomcat virtual path

    I recently learned SpringMVC --> uploading files, I encountered the problem that the image echo cannot be displayed normally...

                            Not allowed to load local resource

Problem Description:

    How to solve chrome report Not allowed to load local resource error


reason:

    1. Chrome does this for security reasons.

    2. It is forbidden to access local files in this way. It seems that the security is guaranteed to a certain extent.


Solution (IDEA tool):


illustrate:

    1. The test file path is the real path of the mapping.

    2./files file path is the mapped virtual path.


Test run:




This will solve the problem. If it is Tomcat, you can refer to the following (I have not verified):

Map the file storage path directory to tomcat as follows:

1. Find the tomcat configuration file (\conf\server.xml) and open it

2. Add the following code between [host] and [/host]: [<Context path="/files" docBase="F:\test" debug="0" reloadable="true"/>]

        Among them: [path] is the path of the mapping, [docBase] is the path where your file is located 

3. Calling method: There is a picture of test.jpg under [F:\test] 

  [The src in the img tag is changed to "/files/test.jpg"]

4. Test ok


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326232394&siteId=291194637