Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

setting attributes and using sendRedirect  RSS feed

 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi , Is this possible to do ?


session.setAttribute("bean",EmpBean);

response.sendRedirect("/myjsp.jsp");// Assuming that myjsp.jsp within the same context/server(part of the web application)

Can i access this EmpBean info in myjsp.jsp page as i am not using RequestDispatcher forward , and only using sendRedirect()???
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, you can . since session is a representation of a loggedin user
 
sandeep yel
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you want to redirect the request to a different URL, but still want to use a session. There is a special URL encoding method just for that.

response.encodeRedirectURL("/BeerTest.do");
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sandeep yel wrote:When you want to redirect the request to a different URL, but still want to use a session. There is a special URL encoding method just for that.

response.encodeRedirectURL("/BeerTest.do");


Thanks for your information seetha,

sandeep , when i want to access other site for example www.google.com , by using encodeRedirectURL("/BeerTest.do") and return type of it into sendRedirect() , we can maintain session id on other site also , but i think we can't carry data as in my case EmpBean into google.com to access it from there??
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seetharaman venkatasamy wrote:yes, you can . since session is a representation of a loggedin user
You're totally wrong.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sandeep yel wrote:When you want to redirect the request to a different URL, but still want to use a session. There is a special URL encoding method just for that.

response.encodeRedirectURL("/BeerTest.do");

This is only applicable if the client has cookies disabled and still then, the URL has to stay in the same context.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RaviNada Kiran wrote:
sandeep yel wrote:When you want to redirect the request to a different URL, but still want to use a session. There is a special URL encoding method just for that.

response.encodeRedirectURL("/BeerTest.do");


Thanks for your information seetha,

sandeep , when i want to access other site for example www.google.com , by using encodeRedirectURL("/BeerTest.do") and return type of it into sendRedirect() , we can maintain session id on other site also , but i think we can't carry data as in my case EmpBean into google.com to access it from there??
No, that is certainly not the case. The session is domain-specific. That would have been a huge security hole otherwise.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bauke Scholtz wrote:
seetharaman venkatasamy wrote:yes, you can . since session is a representation of a loggedin user
You're totally wrong.


Hi Bauke ,

if you dont mind, can you elaborate my fault
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bauke Scholtz for your valuable information on this,

Then how shall i carry the session information outside the domain ??
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pass it (or its identifier if both have a shared datasource) as request parameter or at least as part of request URL. That's all what you can do.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seetharaman venkatasamy wrote:
Bauke Scholtz wrote:
seetharaman venkatasamy wrote:yes, you can . since session is a representation of a loggedin user
You're totally wrong.


Hi Bauke ,

if you dont mind, can you elaborate my fault
A session does in no way represent a logged in user. That you can store the logged in user in there doesn´t make it different.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bauke Scholtz wrote:A session does in no way represent a logged in user. That you can store the logged in user in there doesn´t make it different.


Well Bauke . but you can set the value into the session also (you can get it after the redirect)right ?
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If in the same domain and context (thus also the same session), yes.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks bauke
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your conversation made me more clear on this .Thanks once again to both of you.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!