Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

which session listner to be impletement

 
Samanthi perera
Ranch Hand
Posts: 510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to be loaded the information from database to the system at the start of a ticket purchasing session.
so which type of listner to be impletement?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you tell us which one you were thinking of using and why.
 
Samanthi perera
Ranch Hand
Posts: 510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is my requirment.
You are required to design, implement and test a system to simulate the zone/fare management and ticket purchasing system. Your system must be designed using a database to manage zone and fare information and etc. The information should be loaded to the system at the start of a ticket purchasing session. You should set up your database by hand so it has some initial data with a sufficient variety of information in order to fully demonstrate the functionality that you have implemented
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Samanthi,

We're happy to help you out with your assignment but we won't do it for you.
Have you read the servlet spec to see which listeners are available?
Did you understand what you read?
Do you have any questions about a particular listener that wasn't answered by reading the spec?

After reading about them, which one do you think best suites your needs?
Why?

 
Samanthi perera
Ranch Hand
Posts: 510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think sessionbindinglistner is the best.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is that?

When does a sessionBindingListener fire?
 
Samanthi perera
Ranch Hand
Posts: 510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when we making a new session it fires.
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, check its javadocs for when it fires.
 
Samanthi perera
Ranch Hand
Posts: 510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it fires when session times out or session invalidate.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Samanthi,

There is a link to the servlet spec in my signature.
It shouldn't take more than 15 minutes to search for the various listeners it provides and read up on them.
That's a lot less time than you've already spent trying to get us to do your work for you.

 
Samanthi perera
Ranch Hand
Posts: 510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
still confusing?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you asking me if I'm confused or are you telling me that you're confused?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben Souther wrote:Are you asking me if I'm confused or are you telling me that you're confused?

Still confusing?
 
Samanthi perera
Ranch Hand
Posts: 510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am confused.anyway finally i found the httpsessionlistener is good for my work.
The information should be loaded to the system at the start of a ticket purchasing session
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
Samanthi perera
Ranch Hand
Posts: 510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to add a arraylist reference to the servletcontext .
arraylist contain data retrived by database.
then can i do it implimenting httpsessionlistener in a normal java class?
or should i impliment httpsessionlistener in a servlet?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't do it from a servlet.

Servlets should only ever have to respond to web requests.
Create a class that implements the listener that you want to use.
 
Samanthi perera
Ranch Hand
Posts: 510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my DaoImple class


this is my httpListener class


but i need to access this Arraylist fron anywere in my application.
how to archive this?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you only reading from the database when activeSessions == 1?

What is your intent in doing that?
 
Samanthi perera
Ranch Hand
Posts: 510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i change my listener class


here my static class


i use staic method to store arraylist.
is this good design way?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Samanthi perera wrote:
but i need to access this Arraylist fron anywere in my application.
how to archive this?


Hint: What scope object can be seen by all resources in a servlet application?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Storing things in static variables can cause problems in Java web applications.

The servlet spec provides a better place for you to store them.
Again, hint: What scoped object can be seen from all resources in a servlet application?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben Souther wrote:Why are you only reading from the database when activeSessions == 1?

What is your intent in doing that?


You still haven't answered this question.
 
Samanthi perera
Ranch Hand
Posts: 510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
then only first user loging it get data from database,otherwise each time it gets data from database.
i think it is very resourse consuming.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the data going to be the same for all users or is it going to be specific to each user?

The requirements that you posted lead me to believe that the data will be different for each user.
If not then a session listener is not the right tool for this job.

 
Samanthi perera
Ranch Hand
Posts: 510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
currently it is same for all users.but there are different data tables which is not same data.
anyway if all data are same what is the listner?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Samanthi perera wrote:currently it is same for all users.but there are different data tables which is not same data.

I'm not sure what that means.
Does your app need to be able to work with different data for each user?

Samanthi perera wrote:
anyway if all data are same what is the listner?


Hint: What scoped object can be seen by all resources in a servlet application?
What other listeners did you see when you were reading the spec earlier?
 
Samanthi perera
Ranch Hand
Posts: 510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what that means.
Does your app need to be able to work with different data for each user?


still i am developing database tables too.
so there is some tables data common for all users,and some tables data is specific for some users.

1)anyway if the all data is common it is better to use contextlistener?
2)if the data is specific for each user httpsessionlistener is good?

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic