you are not logged in

G

gk

i am giving a real example.

do you use ebay or any online e-commerce portal.


there you can see a search box. in that search box , you can search for
any items . you get a result page and for each item, you get a "Bye
now" button next to it.

but as soon as you are trying to buy , you'll be getting a prompt for
login page . after your login, you again go back to the same page.


my question is, how we can go back to same page ?

i have a guess for coding..

when a user clicks for "Bye Now", the code checks whether use==null or
not. if(user==null) then response.sendRedirect(/login.jsp) and when the
user logs in what the code would do ?



you know these kind of sequences could arise.

1. user come to site and logs in

2. user did not login first but go for searcing items and then go for
"Buy Now", now he should login and get back the similar page.


its very easy if the user follows step(1)

but How do i code if the user follows step(2) because in that case , he
has to get back the page as soon as he logs in. and how do i know
,whether user is coming via step (1) or via step (2) ? if he comes via
step (2) how do i code ?




thank you
 
I

Ian Mills

gk said:
i am giving a real example.

do you use ebay or any online e-commerce portal.


there you can see a search box. in that search box , you can search for
any items . you get a result page and for each item, you get a "Bye
now" button next to it.

but as soon as you are trying to buy , you'll be getting a prompt for
login page . after your login, you again go back to the same page.


my question is, how we can go back to same page ?

i have a guess for coding..

when a user clicks for "Bye Now", the code checks whether use==null or
not. if(user==null) then response.sendRedirect(/login.jsp) and when the
user logs in what the code would do ?



you know these kind of sequences could arise.

1. user come to site and logs in

2. user did not login first but go for searcing items and then go for
"Buy Now", now he should login and get back the similar page.


its very easy if the user follows step(1)

but How do i code if the user follows step(2) because in that case , he
has to get back the page as soon as he logs in. and how do i know
,whether user is coming via step (1) or via step (2) ? if he comes via
step (2) how do i code ?




thank you
I would think you would keep track of whether the user was logged in in
the session and when a function is called that requires the user to be
logged you would check in the session if this was so and act
accordingly. This means it does not matter which sequence to user takes.
This would also make it possible to force the user to log back in after
a period of inactivity as the session would have timed out.
 
G

gk

yes.

but, say user is not logged in.

user-1 trying to access page1.jsp ==>he gets a login prompt ==>he logs
==>he gets back mypage1.jsp .


user-2 trying to access page2.jsp ==>he gets a login prompt ==>he logs
==>he gets back mypage2.jsp .



user-3 trying to access page3.jsp ==>he gets a login prompt ==>he logs
==>he gets back mypage3.jsp .


so, you see, how difficult it is to track the pages to give back as
soon as the user logs in. because every time user is demanding new
pages.

so if there are lots of pages then its dificult to handle it.
 
G

gk

please clarify you comments

you told ".....whether the user was logged in in
the session and when a function is called that requires the user to be
logged you would check in the session if this was so and act
accordingly......"

whats the code ?

here i am postng the code..but this does not work.

String user = session.getAttribute("user");

if(user==null) response.sendRedirec(/login.jsp)
else
{
// display all the search items here.
}


Now, think, the user==null, and so he is going to the login page by
"response.sendRedirec(/login.jsp)" . now the user logs in there. how
does he get back the previous page !!!!

whats the code i have to write now to get back the previous page ?
 
T

Tim B

gk said:
i am giving a real example.

do you use ebay or any online e-commerce portal.


there you can see a search box. in that search box , you can search for
any items . you get a result page and for each item, you get a "Bye
now" button next to it.

but as soon as you are trying to buy , you'll be getting a prompt for
login page . after your login, you again go back to the same page.


my question is, how we can go back to same page ?

i have a guess for coding..

when a user clicks for "Bye Now", the code checks whether use==null or
not. if(user==null) then response.sendRedirect(/login.jsp) and when the
user logs in what the code would do ?


one way to accomplish this is to append a parameter to the url when
redirecting that indicates either the page the user started at or their
search criteria that was used when displaying their starting page. Put a
hidden field with this value in the login jsp, so when it is submitted to a
servlet or whatever, logic can be done to redisplay the original page to the
user. This appears to be how ebay does it.
 
I

Ian Mills

gk said:
please clarify you comments

you told ".....whether the user was logged in in
the session and when a function is called that requires the user to be
logged you would check in the session if this was so and act
accordingly......"

whats the code ?

here i am postng the code..but this does not work.

String user = session.getAttribute("user");

if(user==null) response.sendRedirec(/login.jsp)
else
{
// display all the search items here.
}


Now, think, the user==null, and so he is going to the login page by
"response.sendRedirec(/login.jsp)" . now the user logs in there. how
does he get back the previous page !!!!

whats the code i have to write now to get back the previous page ?
You could possibly keep track of the next page to go to in the session -
so if the user logs in initially this would be balnk so send him to the
start page otherwise befor doing the re-direct save the page the user
was trying to go to in the session and then redirect to the login page.
Now when the user logs in this parameter would be set so then you could
send another e-direct to go to the required page.
 
G

gk

I
the re-direct save the page the user
was trying to go to in the session and then redirect to the login page.
Now when the user logs in this parameter would be set so then you could
send another e-direct to go to the required page.


you told "save the page "

did you mean saving the name of the page ?
like this

session.setAttribute("pageToAccess","mypage.jsp")

and again ,
when he user logs in i should retrieve this way,

String pagetoaccess=session.setAttribute("pageToAccess");
response.sendRedirect(pagetoaccess);



is this kind of code you are offering ?

please clarify.

thank you
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top