简体   繁体   中英

How do I merge the current request parameters with a new parameter in JSP/JSTL/JQuery?

I have the following URL:

http://127.0.0.1:8080/admin/seller?email=tim%40example.com

I have the following JSP:

<a class="btn btn-primary ${page==pages||pages==0?'disabled':''}" 
  href="?page=${page + 1}">Next</a>

I would like to merge the current query string with page=${page+1} . It is not only just email , it could be many different GET request parameters. How is this possible in JSTL or JSP?

I could create a JQuery event handler for onclick events, but there's got to be an easier way.

I solved it with this, but there's got to be a better way!

<a class="btn btn-primary ${page==pages||pages==0?'disabled':''}" href="javascript:page(${page + 1});">Next</a>

<script>
location.queryString = {};
location.search.substr(1).split("&").forEach(function (pair) {
    if (pair === "") return;
    var parts = pair.split("=");
    location.queryString[parts[0]] = parts[1] &&
        decodeURIComponent(parts[1].replace(/\+/g, " "));
});
function page(p) {
    window.location.queryString.page = p;
    window.location.replace(window.location.pathname + "?" + $.param(window.location.queryString));
}
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM