NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
abhi.uppala
Joined: 21 Oct 2008 Posts: 37
|
Posted: Wed Jan 06, 2010 11:28 am Post subject: Redirection based on session value |
|
|
Hi
I have two pages,page1.jsp and page2.jsp.If a user is in page2.jsp and then tries to access page1.jsp,i need to check for the value of a session variable. If the session variable value is x then he can view page1.jsp,else the user should be redirected to page2.jsp i.e,he should stay in the same page.
How can i achieve this?
I tried to call a javascript function in the onLoad of the <form> and in thar function i checked for the session variable and based on it, i did request.sendRedirect()
But this did not work
Thanks in advance
Abhishek Uppala  |
|
| Back to top |
|
 |
Melongo Annabel Posted via mailing list.
|
Posted: Wed Jan 06, 2010 7:11 pm Post subject: Re: Redirection based on session value |
|
|
You don't need a javascript to do that.
1. First you get the value from the session: X = session.getAttribute('variableName' , enteredValue);
2. if X == x response.sendRedirect("page1.jsp");
else response.sendRedirect("page2.jsp");
Hope this helps.
From: abhi.uppala <address-removed>
To: address-removed
Sent: Wed, January 6, 2010 5:28:48 AM
Subject: [nbj2ee] Redirection based on session value
Hi
I have two pages,page1.jsp and page2.jsp.If a user is in page2.jsp and then tries to access page1.jsp,i need to check for the value of a session variable. If the session variable value is x then he can view page1.jsp,else the user should be redirected to page2.jsp i.e,he should stay in the same page.
How can i achieve this?
I tried to call a javascript function in the onLoad of the <form> and in thar function i checked for the session variable and based on it, i did request.sendRedirect()
But this did not work
Thanks in advance
Abhishek Uppala  |
|
| Back to top |
|
 |
abhi.uppala
Joined: 21 Oct 2008 Posts: 37
|
Posted: Thu Jan 07, 2010 4:05 am Post subject: Re: Redirection based on session value |
|
|
Hi Melongo
This piece of code should be placed in <head></head> or <form></form>
I placed it in <head><script></script></head> but did not work.
Thanks
Abhishek Uppala
| Melongo Annabel wrote: | You don't need a javascript to do that.
1. First you get the value from the session: X = session.getAttribute('variableName' , enteredValue);
2. if X == x response.sendRedirect("page1.jsp");
else response.sendRedirect("page2.jsp");
Hope this helps.
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|