NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Redirection based on session value

 
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users
View previous topic :: View next topic  
Author Message
abhi.uppala



Joined: 21 Oct 2008
Posts: 37

PostPosted: Wed Jan 06, 2010 11:28 am    Post subject: Redirection based on session value Reply with quote

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 Smile
Back to top
Melongo Annabel
Posted via mailing list.





PostPosted: Wed Jan 06, 2010 7:11 pm    Post subject: Re: Redirection based on session value Reply with quote

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 Smile
Back to top
abhi.uppala



Joined: 21 Oct 2008
Posts: 37

PostPosted: Thu Jan 07, 2010 4:05 am    Post subject: Re: Redirection based on session value Reply with quote

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 Smile


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
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo