URL access to a picture in Tomcat that implements a specific path

Source: Internet
Author: User
Tags base64

When using Tomcat as a server, if you do not configure the picture to save the path, the picture is saved in the project path, then the war Package publishing project may cause the loss of the picture, each restart before the picture saved and then copy to the server is obviously inconvenient, you can configure the picture save location, Save the picture to a place outside of the project, by doing the following:

Open the Server.xml file under tomcat-conf and add it under the host node

<context docbase= "G:/upload/images" path= "/images"/>

Docbase is the location where the picture is saved, and path is the way to access the picture.

For example: Upload a picture of test.jpg to the server,

Access Path is http://localhost/images/test.jpg

This not only solves the picture preservation problem, but also can ensure the security of the server.

To achieve a demand, the mobile upload image to the server, the mobile side using Base64 encoding, transmission, service-side decoding, save to disk C:/picture, the mobile end of the request again or return to Base64 past, want to make the image in a URL representation.

Only one simple configuration is required here:

1. Go to Tomcat's installation path to locate the configuration file, and then modify

Locate Server.xml for the following configuration

<Context path="/image" docBase="C:\picture" debug="0" reloadable="true" crossContext="true" />

2. Go to eclipse, locate the Tomcat server under which you are running the project, click and a page will appear, and the page can see the Overview/modules

3. Click Modules, click Add External Web Module, and then enter the path where you stored the image, such as c:/picture, and then restart the server.

Then in the browser input your ip+ set path name + picture, such as I set c:/picture not called/picture, my picture is test.png;

Then I can be ip+/picture/test.png when I visit.

URL access to a picture in Tomcat that implements a specific path

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.