Java Web Access Engineering root directory address __web

Source: Internet
Author: User

Application scenario: The file or directory to be manipulated is placed in a directory of the project, together with the project deployment management.

The easiest way to think of it is System.getproperty ("User.dir"), but this approach is different in terms of publishing and the address to eclipse, where the published Dynamic Web Project is System.getproperty (" User.dir ") value is: d:/eclipse/, for Eclipse is d:/workspace/test01/.


In this case, most of us want to get the root directory address of the Dynamic Web project, and finally get the root directory address.

public string Gettemplatepath () {
		string root = Thread.CurrentThread (). Getcontextclassloader (). GetResource (""). ToString ();
		System.out.println ("Gettemplatepath:--------" +root);
		Return root.substring (Root.indexof ("file") + "file". Length () +2);
	}

The value returned is d:/ide/apache-tomcat-6.0.43/wtpwebapps/devplatform/web-inf/classes/, and then the address is adjusted according to the location where the file/directory is located

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.