JSP path Summary

Source: Internet
Author: User

To reference the path of the current folder, I searched for a lot of information about the JSP path on the Internet and listed it one by one for reference:

The absolute path of the Directory, to the root directory folder of the Directory, such as the Project name: C:/program files/Apache Software Foundation/tomcat 5.5/webapps/projectname, there are two ways to get it:

1) application. getrealpath ("");

2) request. getrealpath ("");

The relative directory of the file name:

File name in the current directory folder: request. getservletpath (); for example:/users. jsp;

File name in the current project (root directory) folder: request. getrequesturi (); for example:/projectname/example. jsp;

Name of the current project (root directory) folder: request. getcontextpath (); for example:/projectname;

All folder names and file names in the current project folder are listed in the Data Group: application. getresourcepaths ("/");

For example: = [/Photo/,/Photo/,/check. JSP,/WEB-INF/,/foot. JSP,/center. JSP,/main. JSP,/data. JSP,/Contract/,/ctrl.htm,/send_check.jsp,/images/,/JS/,/user/,/META-INF/,/index. JSP,/CSS/,/left. JSP,/falsh/,/database/,/work/]

To obtain the current folder, you can use the character function to process it:

If you want to use the upload folder under the current folder (folder is the folder of my current file, and the current file name is upload. jsp:
C:/program files/Apache Software Foundation/tomcat 5.5/webapps/projectname/modules/upload

String parentpath = application. getrealpath (""). Replace ('//','/');

String pathname = request. getservletpath ();

Pathname = pathname. substring (0, pathname. lastindexof ('.'));

Parentpath + = pathname;

Having written so much, I feel that JSP cannot directly obtain the name of the current folder. It is quite uncomfortable to turn so many corners.

Related Article

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.