关于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()获取网站客户的的缓存

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