0

I got a page with comments. I want the user to be able to sort those comments by oldest or newest by clicking on a link that show up in the comment section.

I am already preprocessing views via the url. So when the user browses to book?id=20 it shows the book with the id of 20 from the database.

Going directly to book?id=20&sort=oldest already works. How do I get my JSP to append to the URL upon clicking?

The problem im having is that I can't hardcode them in: for example, if I just coded in <a href="book?id=${param.id}&show=newest">Newest</a> it will disrupt other query strings. What if the user is already at the URL book?id=20&stars=5 (shows comments with the rating of 5 stars).

I'd like the JSP to just append onto the URL so that it includes any current queries, so for example: user is at currently at book?id=20&stars=5, user then clicks sort by oldest, then the JSP appends &sort=oldest making it book?id=20&stars=5&sort=oldest.

1 Answer 1

1

You can do it with something like that:

<a href="book?id=${param.id}&show=newest" onclick="this.href=this.href+'&sort=oldest'">Newest</a>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.