• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSTL URL previous page  RSS feed

 
Zet Su
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello together,

is it possible to save the complete previous URL in a variable? I make a forum with 3 different pages. When the user is on page 1 he can go to page 2 or 3. On all pages there is a link named "Back" and should bring the user to the previous page. This is a specification from my teacher. I tried this here:
<c:set var="refererPage" scope="request" value="${request.getHeader}"/>
<c:out value="${refererPage}"/>
But the variable "referPage" is empty :/

I hope someone can help me!
 
K. Tsang
Bartender
Posts: 3633
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you know the order of the pages in advanced as in form filling step by step then such page info can be set in the controller and use a hidden field in the html form.

If you doing pagination then its totally different.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What did you expect this:to do for you?
 
Zet Su
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear: i copied these commands from another website and thought this could help me. I thought that the command request.getHeader will show the actual url.

all: I must make a little "forum" for school. The first website shows a forum with all threads. The second page shows the threads and is dynamic (for example showthread.jsp) If you click the first thread you see the website with the id=1 and the contribution, when you click the second thread with id=2 a.s.o. The url "back" should bring you back to the first webpage where you can see all threads. On the second page where the whole thread is shown you see the answers to. When you click on these answers the page 2 (show thread) is changed (id=3). Here is the "url "back" to, but now you will not be redirect to the first page but to the second page with the thread you first clicked!!! If you click on the url "answer", you will get to the page answer.jsp. And here is the url "back" too. When the user click this url, then he should go back to the thread he visited.

Example: User A goes to forum.jsp clicks on Thread 1. Now he sees thread 1 and clicks on answer. A is now on page 2 and want to go back to the thread. How can i make this? Thats why i need the "previous url". I thought i can save the previous url and if the user clicks on back he will be redirected to this url.

Sorry for my bad english, iam from germany and english is not my best language! If you have questions, than i try to response quick.
 
Stefan Evans
Bartender
Posts: 1834
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Bear has hinted, ${request.getHeader} will not get you the referring page.
It is likely you are confusing the expression language with java code.

There is a method in the Java Servlet API: request.getHeader, however that takes a parameter being the name of the header you are after. In this case the header you want is "referer", so the correct java code would be request.getHeader("referer")

However we are in EL, not java.
In a JSP page, there is an implicit EL variable "headers" which you can use instead of request.getHeader (it is backed by the same values). However again you need to specify the name of the header you are after.
So the value of the referer header in EL would be : ${headers.referer}

Ok, that should answer your obvious question: how do I get the referring page.

However I am not convinced that you need this value.
Two things you can do
#1 - use the browsers back button. That's what it is for, and if you design your app right, it normally works pretty well.
#2 - you probably know the url the back button needs to go to already. Why not just specify it rather than try and use "the page I came from" ?

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!