ServletContext reading a resource file in a web App

Source: Internet
Author: User

Note: The read path cannot be this path, because this file is not run after the SRC path, but under classes

However, this is also not possible because the file startup starts from the virtual machine and does not have this path under the virtual machine unless the classes file containing the properties is copied to the virtual machine path

So, using ServletContext to read

Usually in the project, we use ServletContext to get the resource path, and then read the resource file in the traditional way.

In this, is the template code that gets the content with ServletContext, is fixed

Class loader: Not suitable for large files because the class file is too large to load directly into the virtual machine, which can lead to memory overflow

And, with the ClassLoader, the class is loaded only once, so the updated data cannot be obtained, so the resource file location is usually obtained in the same way that the class is loaded, and then the updated data is obtained in the traditional way.

ServletContext reading a resource file in a web App

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.