zoukankan      html  css  js  c++  java
  • jsp中如何取得当前页面完整的URL

    JSP页面
    <% String url = request.getScheme()+"://"+ request.getServerName()+request.getRequestURI()+"?"+request.getQueryString(); %>


    JAVA代码

        String basePath = request.getScheme()+"://"+request.getServerName();
        String    gotoURL = request.getRequestURI();
        
        gotoURL = gotoURL.replaceAll("//", "/");
        if(gotoURL.indexOf("/WEB-INF/jsp/") != -1){
            gotoURL = gotoURL.replace("/WEB-INF/jsp/","/");
            gotoURL = gotoURL.replace(".jsp",".shtm");
        }
        gotoURL = basePath+gotoURL;
        String queryStr = request.getQueryString();
        if(queryStr!=null){
            gotoURL = gotoURL +"?"+queryStr;
        }
        try {
            gotoURL = URLEncoder.encode(gotoURL,"UTF-8");
        } catch (Exception e1) {
            e1.printStackTrace(); 

        } 

  • 相关阅读:
    P2813 母舰
    P5367 【模板】康托展开
    P1816 忠诚
    P3865 【模板】ST表
    P1913 L国的战斗之伞兵
    P4939 Agent2
    P1894 [USACO4.2]完美的牛栏The Perfect Stall
    P5017 摆渡车
    P1330 封锁阳光大学
    P5018 对称二叉树
  • 原文地址:https://www.cnblogs.com/wuxiang/p/4409262.html
Copyright © 2011-2022 走看看