Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using a hidden field to store the url in jstl

 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi folks,
Im trying to store the url of the previous page in a hidden field , so that I may access it after authentication , in the eventuality of a user trying to access a secure web page . Any clue on how I would go about retreiving the url of the previous page using jstl would be appreciated.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why aren't you using the session for this?
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear ,
Thank you for your suggestion. But how do I go about putting the URL in to the session in that case?
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Paul !But , where exactly would I put this code? In the servlet associated with the login page , I handle the authentication in the doPost method . However, upon submitting the page I get the value of the String previousPage as in the previous example as null.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I figured that "how do I go about putting the URL in to the session in that case?" wasn't really your question. So could you step back a bit and figure out what your actual question is? And then tell us, complete with details? One detail which is conspicuously missing is what you mean by "previous page", for example.
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well , let me explain my problem a bit more clearly,maybe you can help me figure out an alternative solution than the one I'm currently trying to implement.
My web application is currently secured through a filter, where in the filter checks if a valid user is present by examining the session and allows the user to progress through the application as long he's validated .
Now , when someone tries to access a protected page he/she is thrown off to the login page for authentication , but the problem I face currently is that post authentication the user is redirected to a common page , rather than the initial protected page that s/he had requested.
Is there a way where I can send the user to the page he initially requested rather than the common page ?
I was hoping to store the value of the page that the user had initially requested in a hidden field , which I hope validates my initial question of storing the previous url in a hidden field.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, why not just have the filter store the URL (don't forget any request parameters that need to be recreated) in the session?
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps it's not all that obvious... store the URL in the session before you redirect to the login page.
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Again, why not just have the filter store the URL (don't forget any request parameters that need to be recreated) in the session?

Hi Bear and Paul,
I've tried to do something like the both of you've suggested, in my filter.
Here's what I've done in my filter common to all the secure pages
.
However , I hoped that I would be able to see the url of the previous page , every time I moved through a secure page , but the previous page string does not seem to print. I guess I'm missing something fundamental here . ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carefully examine the logic of your method. Is the code in all the right places?
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vic Hood wrote:I guess I'm missing something fundamental here


I think so. For one thing I don't see where you assign a value to the "previousPage" variable, which would explain why you're not seeing anything meaningful when you display it. I don't have any suggestions about that; I already asked you to explain what "previous page" meant and I haven't seen an explanation yet. So you should first try to produce an explanation of what it means, and then write some code to assign that to the variable. And do take note of the last suggestion I made.
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thank you for your replies .
To answer's Paul's question , by 'previousPage' i mean the url of the previous page , and as suggested by you in an earlier post below.
Paul Clapham wrote:

I try to obtain the url of the previous page and place it into the session
As for Bear's question , this is what I intend to do , I try to get the value of the previous page in the url , if the user is authenticated ,then assign it to a string of the name 'previousPage' and print it , after that I go about processing the filter request using chain.doFilter . I guess I'm missing something in between .?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is it you want to be able to retrieve the value? Have you checked that you are setting the value in the right place?

(Hint: the answer is no.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic