تقدم هذه المقالة Java للحصول على عنوان URL للطلب والحصول على مسار جذر الخادم ، ويعطي أمثلة.
1. احصل على عنوان URL لهذا الطلب
request requesturl = request.getScheme () // البروتوكول المستخدم بواسطة الرابط الحالي + ": //" + request.getServerName () // عنوان الخادم + ": GetCon TextPath () // اسم التطبيق ، إذا كان اسم التطبيق + request.getServletpath () // عنوان URL النسبي + "؟
مثال:
http://127.0.0.1:8080/world/index.jsp؟name=lilei & sex = 1 <context path = "World" "؛ request.getServerName () =" 127.0.0.1 "؛ request.getServerPort () =" 8080 "؛ request.getContextPath () =" word "؛ ) = "الاسم = Lilei & Sex = 1" ؛ "debug =" 0 "relaAdable =" true "/> request.getScheme () =" http "؛ request.getServerName () =" 127.0.0.1 "؛ request.getServerPort () =" 8080 "؛ ) = "" "؛ request.getServletPath () =" world/index.jsp "؛ request.getquerystring () =" name = lilei & sex = 1 "؛
2. احصل على مسار جذر الخادم
<٪ string path = request.getContextPath () ؛
استخدم على النحو التالي:
<Head> <link roth = "stylesheet" type = "text/css" href = "<٪ = basepath ٪> static/css/framework/temes/easyui.css"> <link et "type =" text/css " href = "<٪ = basepath ٪> static/css/framework/turmes/icon.css"> <link r = "stylesheet" type = "text/css" href = /base.css "> <script src =" <٪ = basepath ٪> static/javascript/framework/jquery.min.js /JavaScript/Framework/jQuery.Asyui.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>
ما ورد أعلاه هو طريقة Java التي تم الحصول عليها عن عنوان URL ومسار جذر الخادم.