本文共 520 字,大约阅读时间需要 1 分钟。
访问页面地址:http://localhost:8080/my/index.jsp 页面主要代码及注释: <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; /* request.getScheme()可以返回当前页面使用的协议;默认返回http,SSL时返回https; request.getServerName()可以返回当前页面所在的服务器的名字; request.getServerPort()可以返回当前页面所在的服务器使用的端口,就是项目在服务器上发布的 端口,或者在本地tomcat容器运行时发布的端口,我用的是8081; request.getContextPath()可以返回当前页面所在的应用的名字; */ %> <p> <%=path %> <br> <%=basePath %> </p> 运行后的输出结果: /my http://localhost:8080/my/转载地址:http://bfkmf.baihongyu.com/