Java Servlet obtains various server path information

Source: Internet
Author: User
Package COM. shop. uitl; import javax. servlet. HTTP. httpservletrequest; import Org. apache. struts2.servletactioncontext; public class serverurl {/*** get the basic URL of the Service * @ Param Request * @ return */public static string getserverpath (httpservletrequest request) {string Path = request. getcontextpath (); string basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/"; return basepath ;} /*** get the URL address with a directory * @ Param Request * @ Param directory * @ return */public static string getserverpath (httpservletrequest request, string directory) {string Path = request. getcontextpath (); string basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/"; return basepath + directory + "/";} /*** get the root path of the server * @ Param Request * @ Param directory * @ return */public static string getservercontextpath (httpservletrequest request) {string Path = request. getcontextpath (); return path;}/*** obtain the local disk path of the server * @ Param Request * @ return */public static string getdiskpath (httpservletrequest request) {string Path = servletactioncontext. getservletcontext (). getrealpath ("/"); return path;}/*** get the local disk path of the server, folder * @ Param Request * @ Param directory * @ return */public static string getdiskpath (httpservletrequest request, string directory) {string Path = servletactioncontext. getservletcontext (). getrealpath ("/"); Return Path + directory + "/";}}

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.