If you don't have any particular reason, why don't you use javascript to do this?
<FORM> <INPUT TYPE="button" VALUE="Go Back" onClick="history.go(-1)"> </FORM>
You can refer to some other ways to do it in javascript: http://www.comptechdoc.org/independent/web/cgi/javamanual/javahistory.html
The reason it's cool is that you don't have to handle this piece of "back" code in your server. You let browsers handle it for you.
If you insist in doing so in plain java, I think session is the best way to do it. If you would like to remember the whole path, all you have to do it to store an Stack
in your session, and name it history or something alike. You pop out one URL whenever the user click back, and push an URL when the user click into a new URL.