获取服务器路径的方式 【记录】

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/huyande123/article/details/81180924

JSP页面获取服务器路径的方式

1.basePath方式

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

在url加入<%=basePath%>如:http://192.168.66.66:8089/xinfang/

2.直接请求服务器路径

${pageContext.request.contextPath}

服务端获取服务器路径的方式

//获取远程服务器IP和端口
String serverIp=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort();

http://localhost:80/images/ocrtemp_1.png

获取本机IP地址

InetAddress address = InetAddress.getLocalHost();
String hostAddress = address.getHostAddress();

  192.168.66.66

SpringBoot 

window.location.origin

猜你喜欢

转载自blog.csdn.net/huyande123/article/details/81180924