aspose file tools*
The moose likes Servlets and the fly likes which session listner to be impletement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "which session listner to be impletement" Watch "which session listner to be impletement" New topic
Author

which session listner to be impletement

Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
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

Joined: Dec 11, 2004
Posts: 13410

Why don't you tell us which one you were thinking of using and why.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Jan 08, 2010
Posts: 510
i think sessionbindinglistner is the best.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Why is that?

When does a sessionBindingListener fire?
Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
when we making a new session it fires.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42930
    
  68
No, check its javadocs for when it fires.
Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
it fires when session times out or session invalidate.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Jan 08, 2010
Posts: 510
still confusing?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Are you asking me if I'm confused or are you telling me that you're confused?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Jan 08, 2010
Posts: 510
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

Joined: Dec 11, 2004
Posts: 13410

Good luck with your project.
Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Jan 08, 2010
Posts: 510
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

Joined: Dec 11, 2004
Posts: 13410

Why are you only reading from the database when activeSessions == 1?

What is your intent in doing that?
Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
i change my listener class


here my static class


i use staic method to store arraylist.
is this good design way?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Jan 08, 2010
Posts: 510
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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Jan 08, 2010
Posts: 510
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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Jan 08, 2010
Posts: 510
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?

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: which session listner to be impletement