Adding to request parameters in a jsp
How can I add parameters to a link in a 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 in there (or whatever) already I don't want to lose the other parameters when I sort. How do I go about that? Do I have to use <% requ开发者_开发技巧est.getUrl %> or something like that?
Use HttpServletRequest#getQueryString()
.
<c:url value="/Top.jsp?sortBy=downloads&sortOrder=desc&${pageContext.request.queryString}" />
You may use array of query string params(must determinate all params manually, its OK if params not so much :) in jstl
<a href="<c:url value='/Top.jsp?sortBy=${param.sortBy}&sortOrder=${param.sortOrder}&nextParam=${param.nextParam}'/>">
In the case of using ${pageContext.request.queryString}, you may get duplicate params in query string
精彩评论