zoukankan      html  css  js  c++  java
  • 获取页面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  
  • 相关阅读:
    luogu1196 银河英雄传说 (并查集)
    [BZOJ2243][SDOI2011]染色
    [BZOJ1879] [Sdoi2009]Bill的挑战
    [Noip2003] 侦探推理
    [Noip2005] 篝火晚会
    [JZOJ100047] 【NOIP2017提高A组模拟7.14】基因变异
    [九省联考2018]一双木棋chess
    [Noip2009] 靶形数独
    [Luogu2737] [USACO4.1]麦香牛块Beef McNuggets
    [BZOJ3109] [cqoi2013]新数独
  • 原文地址:https://www.cnblogs.com/JealousGirl/p/jUrl.html
Copyright © 2011-2022 走看看