首页 > 其他分享 >request.getScheme()的使用方法

request.getScheme()的使用方法

时间:2022-10-17 19:13:51浏览次数:50  
标签:返回 request getScheme 当前 使用 方法 页面

今天在修改bug时,发现程序使用了 request.getScheme() 。不明白是什么意思,在google 搜索了一下。现在明白了。整理如下:

1、request.getScheme() 返回当前链接使用的协议;比如,一般应用返回http;SSL返回https;


2、在程序中的应用如下:

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

3、复习一下request 的常用方法:

request.getSchema()可以返回当前页面使用的协议,http 或是 https;

request.getServerName()可以返回当前页面所在的服务器的名字;

request.getServerPort()可以返回当前页面所在的服务器使用的端口,就是80;

request.getContextPath()可以返回当前页面所在的应用的名字;



例如:

<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">

标签:返回,request,getScheme,当前,使用,方法,页面
From: https://www.cnblogs.com/sxhxh/p/16800252.html

相关文章