Este artigo apresenta o Java para obter o URL da solicitação e obter o caminho raiz do servidor e dá exemplos.
1. Obtenha o URL deste pedido
String requesturl = request.getscheme () // o protocolo usado pelo link atual + ": //" + request.getServername () // endereço do servidor + ":" + request.getServerport () // número da porta + request. getCon TextPath () // Nome do aplicativo, se o nome do aplicativo é + request.getServletPath () // o URL relativo + "?"
Exemplo:
http://127.0.0.1:8080/world/index.jsp?name=lilei & Sex = 1 <contexto Path = "World" docbase = "/home/webApps" Defug = "0" uest. "; request.getServerName () =" 127.0.0.1 "; request.getServerport () =" 8080 "; request.getContextPath () =" word "; ) = "Nome = lilei & sexo = 1"; "DEBUG =" 0 "relAadable =" true "/> request.getscheme () =" http "; request.getServername () =" 127.0.0.1 "; request.getServerport () =" 8080 "; req uest.getContextPath ( ) = = "" "; Request.getServletPath () =" World/Index.jsp "; request.getQueryString () =" nome = lilei & sexo = 1 ";
二、获取服务器根路径
< % String Path = request.getContextPath ();
Use o seguinte:
<head> <link roth = "stylesheet" type = "text/css" href = "<%= bashepath%> static/css/estrutura/temas/easyui.css"> <link et "type =" text/css " href = "<%= bashepath%> static/css/estrutura/temas/icon.css"> <link r = "stylesheet" type = "text/css" href = "<%= basepath %%%> static/csss /Base.css "> <script src =" <%= bashepath%> static/javascript/estrutura/jQuery.min.js "> </script> <script src =" <%= basepath %> stati%> stati c /javascript/estrutura/jquery.easyui.minmin.min.js "> </script> <script src =" <%= baseepath%> static/javascript/estrutura/easei-lang-zh_cn.js "> </> </> </ /> script> <script src = "<%= baseepath%> static/javascript/estrutura/easyui-til.js"> </script> </head>
O acima é o método de Java obteve o URL da solicitação e o caminho da raiz do servidor.