Get path in Java

Source: Internet
Author: User

The content comes from snannan_268

Keyword: Get path in Java to get path in Java:


1.jsp Get path:
 
Take the project name test as an example:

(1) Get the full path of the current page that contains the project name: Request.getrequesturi ()
Results:/test/test.jsp
(2) Get project name: Request.getcontextpath ()
Result:/test
(3) Get the current page in the same directory as the full name: Request.getservletpath ()
Results: If the page is in the JSP directory/test/jsp/test.jsp
(4) Get the full path of the server on which the page is located: Application.getrealpath ("page. jsp")
Results: d:/resin/webapps/test/test.jsp
(5) Get the absolute path of the server on which the page is located: Abspath=new java.io.File (Application.getrealpath (Request.getrequesturi ())). GetParent ();
Result: D:/resin/webapps/test

2. Gets the path in the class:

(1) The absolute path of the class: Class.class.getClass (). GetResource ("/"). GetPath ()
Results:/d:/test/webroot/web-inf/classes/pack/
(2) Get the project path: System.getproperty ("User.dir")
Result: d:/ TEST

3. Obtain the path in the servlet:

(1) Get the Project catalog: Request.getsession (). The Getservletcontext (). Getrealpath ("") parameter can be specific to the package name.
Result: E:/tomcat/webapps/test
(2) Get IE Address bar address: Request.getrequesturl ()
Results: http://localhost:8080/TEST/test
(3) Get relative Address: Request.getrequesturi ()
Result:/test/test

Get path in Java

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.