Adding request parameters to jsp

How to add parameters to link in jsp without overwriting what is already there?

For example, I have this now:

<a href="<c:url value='/Top.jsp?sortBy=downloads&sortOrder=desc'/>">

But if they have a search term (or something else), I do not want to lose other parameters when sorting. How should I do it? Should I use <% request.getUrl%> or something like that?

+3
source share
2 answers

Use HttpServletRequest#getQueryString().

<c:url value="/Top.jsp?sortBy=downloads&sortOrder=desc&${pageContext.request.queryString}" />
+5
source

You can use an array of query string parameters (you need to define all parameters manually, its OK, if there are not many parameters :) in jstl

<a href="<c:url value='/Top.jsp?sortBy=${param.sortBy}&sortOrder=${param.sortOrder}&nextParam=${param.nextParam}'/>">

${pageContext.request.queryString}

+1

Source: https://habr.com/ru/post/1778845/


All Articles