首页 > Web开发 > 详细

jsp中如何取得当前页面完整的URL

时间:2015-04-09 13:27:57      阅读:167      评论:0      收藏:0      [点我收藏+]
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(); 

    } 

jsp中如何取得当前页面完整的URL

原文:http://www.cnblogs.com/wuxiang/p/4409262.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!