• 获取页面URL两种方式


    以请求http://localhost:8080/doctor/demo?code=1为例


    一:用java代码获取

     1     //获取URL中的请求参数。即?后的条件    code=1
     2     String queryString = request.getQueryString() ;
     3 
     4   //获取URI。 /doctor/demo
     5   String requestURI = request.getRequestURI() ;
     6 
     7   //获取URL(不带请求参数)。即协议+ip地址+端口号+请求方法    http://localhost:8080/doctor/demo
     8   StringBuffer requestURL = request.getRequestURL() ;
     9 
    10   //返回调用servlet请求的URL部分。/doctor/demo
    11   String servletPath = request.getServletPath() ;
    12 
    13 
    14   //获取ip地址。    localhost
    15   String serverName = request.getServerName();
    16 
    17   //获取请求协议    http
    18   String scheme = request.getScheme();
    19 
    20   //获取端口号    8080
    21   int serverPort = request.getServerPort();

    二:在页面中获取
      

     1     //设置或获取对象指定的文件名或路径。    /doctor/demo
     2   window.location.pathname;
     3 
     4   //设置或获取整个 URL 为字符串。http://localhost:8080/doctor/demo?code=1
     5   window.location.href;
     6 
     7   //设置或获取与 URL 关联的端口号码。8080
     8   window.location.prot;
     9 
    10   //设置或获取 URL 的协议部分。http:
    11   window.location.protocol;
    12 
    13   //设置或获取 location 或 URL 的 hostname 和 port 号码。localhost:8080
    14   window.location.host;
    15 
    16   //设置或获取 href 属性中跟在问号后面的部分。?code=1
    17   window.location.search;
    18 
    19  
  • 相关阅读:
    ecshop与jquery冲突的解决方案
    ecshop_dwt_lbi模板添加
    ecshop模板基础知识
    bcc-tools工具之pidpersec
    bcc-tools工具之runqlen
    bcc-tools工具之runqlat
    bcc-tools工具之funccount
    cgroup介绍之为什么需要了解cgroup
    bcc-tools工具之funcslower
    git patch制作相关简介
  • 原文地址:https://www.cnblogs.com/JealousGirl/p/jUrl.html
Copyright © 2020-2023  润新知