In diesem Artikel wird Java vorgestellt, um die Anforderungs -URL zu erhalten und den Server -Root -Pfad zu erhalten, und gibt Beispiele an.
1. Holen Sie sich die URL dieser Anfrage
String Requesturl = Request.getScheme () // Das vom aktuelle Link verwendete Protokoll + ": //" + request.getServerName () // Serveradresse +: " + request.getServerport () // Portnummer + Anfrage. GetCon textPath () // Anwendungsname, wenn der Anwendungsname + Request.getServletPath () // die relative URL + " + Request.getQueryString ();
Beispiel:
http://127.0.0.1:8080/world/index.jsp?name=lilei & sex = 1 <context path = "world" docbase = "/home/webugs" Defug = "0" Uest. "; Request.GetSerVername () =" 127.0.0.1 "; Request.getServerport () =" 8080 "; Request.getContextPath () =" Word "; ) = "name = lilei & sex = 1"; "Debug =" 0 "relaadable =" true "/> request.getscheme () =" http "; request.getServername () =" 127.0.0.1 "; Anfrage. ) = "" "; Request.getServletPath () =" World/index.jsp "; request.getQueryString () =" name = lilei & sex = 1 ";
2. Holen Sie sich den Server -Root -Pfad
< % String Path = Request.getContextPath ();
Verwenden Sie wie folgt:
<Head> <link roth = "stylesheet" type = "text/css" href = "<%= basepath%> static/css/Framework/Themen/easyui.css"> <link et "type =" text/csS " href = "<%= basepath%> static/css/Framework/Themen/icon.css"> <link r = "styleSheet" type = "text/css" href = "<%= Basepath %%%> static/css /Base.css "> <script src =" <%= basepath%> static/javaScript/Framework/jQuery.min.js "> </script> <script src =" <%= Basepath%> Stati%> Stati c /JavaScript/Framework/jQuery.easyui.min.min.js "> </script> <script src =" <%= basepath%> static/javaScript/Framework/Easyi-Lang-Zh_cn.js "> </> </> < /> script> <script src = "<%= basepath%> static/javaScript/Framework/easyui-util.js"> </script> </head>
Die oben genannte Methode von Java hat den Anforderungs -URL- und Server -Root -Pfad erhalten.