当需要传递url地址的时候,比如修改带有分页的帖子后。需要传递页码当修改完毕后可以跳回修改的页面。当有&这个符号时。request只能取得不到这个符号,和这个符号的内容。

比如传递的url地址

http://localhost/newbbs/update.jsp?id=32&urlname=http://localhost/newbbs/articledetailflat.jsp?rootid=30&pageno=2

 

通过request.getParmeter("urlname");

只能取得http://localhost/newbbs/articledetailflat.jsp?rootid=30 无法取得&后面的pageno=2

我想到的方法是取得前转换一下,在使用前再转换一下。

取得前&转换为-

//JSP页面,获得当前页面的url地址

   String url = request.getRequestURL().toString();
     if(request.getQueryString()!=null){
         url += "?" + request.getQueryString();
         url = url.replaceAll("&","-");//转换url

    System.out.println(url);

 http://localhost/newbbs/articledetailflat.jsp?rootid=30-pageno=2

 

//当使用url时候,再转换回来

url=url.replaceAll("-", "&");

 http://localhost/newbbs/articledetailflat.jsp?rootid=30&pageno=2

posted on 2014-12-17 21:47  火拳艾斯  阅读(306)  评论(0编辑  收藏  举报