이 기사는 요청 URL을 얻고 서버 루트 경로를 얻기 위해 Java를 소개하고 관심있는 친구들이 다음 내용에서 배울 수 있습니다.
1.이 요청의 URL을 받으십시오
String requestUrl = request.getScheme () // 현재 링크 + ": //" + request.getServerName () // 서버 주소 + ":" + request.getServerport () // 포트 번호 + 요청. getCon TextPath () // 응용 프로그램 이름이 + request.getServletPath () 인 경우 // 상대 URL + "?"
예:
http://127.0.1:8080/world/index.jsp?name=lilei & sex = 1 <context path = "world"docbase = "/home/webapps"defug = "0"http "; request.getServerName () ="127.0.0.1 "; request.getServerport () ="8080 "; request.get.getContextPath () ="word "; tservletPath () ="index.jsp "; request.getQueryString ) = "lilei & sex = 1"; "debug ="0 "relaadable ="true "/> request.getScheme () ="http "; request.getServerName () ="127.0.0.1 "; request.getServerport () ="8080 "; req uest.getContextPath (getContextPath). ) = "" "; request.getServletPath () ="world/index.jsp "; request.getQueryString () ="name = lilei & sex = 1 ";
2. 서버 루트 경로를 가져옵니다
< % string path = request.getContextPath ();
다음과 같이 사용하십시오.
<head> <link roth = "Stylesheet"유형 = "text/css"href = "<%= basepath%> static/css/framework/temes/easyui.css"> <link et "type ="text/css " href = "<%= basepath%> static/css/framework/treess/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 c. /javaScript/framework/jquery.easyui.min.min.js "> </script> <script src ="<%= basepath%> static/javascript/framework/easei-lang-zh_cn.js "> </> < /> script> <script src = "<%= basepath%> static/javaScript/framework/easyUi-util.js"> </script> </head>
위는 Java가 요청 URL 및 서버 루트 경로를 얻었습니다.