關於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>0){
        for(int i=0; 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()獲取網站客戶的的緩存

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章