• Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlets  RSS feed

 
ankita balaji
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai everybody,
Good Afternoon.I have a small doubt regarding session tracking.I maintained a session for username in my login page and wanted to call that username in my feedback page.The main thing is that there is no connection at all between my login page and feedback page.Is it possible that I will get the username in my feedback page from login page??
Can anyone kindly help me in this aspect??
Thank you.
 
Fisher Daniel
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Yes, you can store the information of user into session object.
You can use HttpServletResponse method setAttribute(String name, Object object)..
And this response object can accessed in all jsp page within a web application.
And.. HttpServletResponse method getAttribute(String name) will return the object which is inserted before.

Hope this helps
Correct me if I am wrong...

thanks
daniel
[ October 26, 2004: Message edited by: Fisher Daniel ]
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if userId is in your session then you can get the userId at any page by

session.getAttribute("sesUserId")

for placing userId in session you can do it by

session.setAttribute("sesUserId",userId)

hope this helps...
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Fisher Daniel:

Yes, you can store the information of user into session object.
You can use HttpServletResponse method setAttribute(String name, Object



Correct me if I am wrong...




daniel,

I think it really need a correction

and setAttribute method belongs to javax.servlet.http.HttpSession
 
ankita balaji
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai Shailesh,
Iam really thankful to you for your quick response and your help.But Iam not able to get the user Id for which I have set the session in my login page.Can you please help me in this aspect???
Originally posted by Shailesh Chandra:
if userId is in your session then you can get the userId at any page by

session.getAttribute("sesUserId")

for placing userId in session you can do it by

session.setAttribute("sesUserId",userId)

hope this helps...
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't find any reason for which you are not able to get userId.

you will not get userId if session is being different.

can you verify that you are in same session.

try to print session.getId() on your both page if this is same then you should get userId in session.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IF your "feedback" page is in a different web application it won't be able to see the same session as the "login" page. You could use a c ookie to hold on to the user name, but only if you configure the c ookie to apply to the whole site instead of just one web application. See the javax.servlet.http.C ookie javadocs.
(Note that I had to add the space after the c to make the forum software happy)
Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!