Assuming you have one JSP for all links, do something like this:
main.jsp:
<ul>
<li><a href="detail.jsp?link=page1">Page 1</a></li>
<li><a href="detail.jsp?link=page2">Page 2</a></li>
</ul>
detail.jsp:
<h1>I am on Detail Page</h1>
<% String link = request.getParameter("link"); %>
Then use this variable as per your need.