• Post Reply Bookmark Topic Watch Topic
  • New Topic

Access request object from HttpSessionListener  RSS feed

 
Divith Shetty
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can anyone please tell me how to access request parameter inside HttpSessionListener, as i have to set the session attribute based on that request parameter.


Thanks in advance
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't. The session listener can be 'fired off' when there is no request present, but the opposite is not true.

ie from a request you can access the session, so changes should be made in this direction, not the other way.

Do not try to store the request on the session or mix the request and session listener in the same class as these would be dangerous ideas.
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi BTW, your name does not follow the Javaranch naming policy please change it
here.
Also please go through the Ask good questions link below.
Thanks.
 
Divith Shetty
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not setting request parameter as a session attribute. Instead i am doing some LDAP query based on the request parameter and the output of the query is stored in session attribute.
SO i thought HttpSessionListener is the better way to go. Then where should i set the session attribute?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Divith", please check your private messages for an important administrative matter.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by BTW:
I am not setting request parameter as a session attribute. Instead i am doing some LDAP query based on the request parameter and the output of the query is stored in session attribute.
SO i thought HttpSessionListener is the better way to go.

To go for what? You haven;t explained exactly what it is you are trying to do. Do you know what a session listener actually does?

If you are trying to store a parameter passed in a request, you'd set it into the session in the handler (doGet or doPost) for that request.
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Divith, please change your display name so as to follow the ranch policy.

Hope this helps
 
Divith Shetty
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. Let me explain it properly

Users logs into the application with his empid. Once he logs in i have to find the empname, city ect by seaching LDAP using his empid which will be stored in request object which i am retrieving by request.getUserPrincipal().getName();.

Users may not enter to the same page all the time like, he can log into http://localhost:8080/App/Myapp or even he can log into http://localhost:8080/App/Myapp/AddNew. And i cannt place the code to look for the details(empName,city etc) in each possible servlet. That means i have to place the code in a place which will execute once new session starts. And as HttpSessionListener listens to any new session creation i thought i can place the code in the session listener class. But i will not be having access to request object.

So i want to know where can i set the session attributes? I hope this post explains everything. If it is not please let me know your doubt as it is very important.

Thanks in advance
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Divith, please read your private messages.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Divith:
And i cannt place the code to look for the details(empName,city etc) in each possible servlet.
That's what servlet filters are for.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!