天天看點

關于jsp中request.getContextPath()、request.getSchema()、request.getCookies()的意思

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
    String ip=request.getRemoteAddr();
    Cookie cookie[]=request.getCookies();
    String username="";
    if(cookie!=null && cookie.length>){
        for(int i=; i<cookie.length; i++){
            if("username".equals(cookie[i].getName())){
                username=cookie[i].getValue();
                break;
            }
        }
    }
 %>
           

request.getContextPath()擷取項目名稱;

request.getSchema()可以傳回目前頁面使用的協定,http 或是 https;

request.getServerName()可以傳回目前頁面所在的伺服器的名字;

request.getServerPort()可以傳回目前頁面所在的伺服器使用的端口,預設80;

request.getRemoteAddr()擷取ip,比如本地的127.0.0.1

request.getCookies()擷取網站客戶的的緩存