aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes how we can get notification of an event listener at web browser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "how we can get notification of an event listener at web browser" Watch "how we can get notification of an event listener at web browser" New topic
Author

how we can get notification of an event listener at web browser

pradeep singh
Ranch Hand

Joined: Oct 23, 2007
Posts: 339
Hi everybody
Can anybody tell me how we can get notification of an event listener at web browser( means notification display at web browser)?


SCJP 5.0(75%), SCWCD 5.0(88%)
Bobby Sharma
Ranch Hand

Joined: Mar 18, 2008
Posts: 574
    
    1

please throw some more lights on your question.

by the way, did you mean HttpSessionListener?

I think HF has an example regarding this.

best regards,
omi


Back to Java , again.
Garlapati Ravi
Ranch Hand

Joined: Mar 05, 2008
Posts: 171
pradeep,
what type of event listener you mean ?


Ravi Kumar
SCWCD 5 - 89%, SCJP 1.4 - 90%
pradeep singh
Ranch Hand

Joined: Oct 23, 2007
Posts: 339
Hi
Any event listener like HttpSessionAttributeListener,ContextAttributeListener etc. .But want to get notification on browser(means in a jsp page ) showing some message .Please explain with an example.
[ May 10, 2008: Message edited by: pradeep singh ]
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
If you're asking what I think, you cannot do this with just Java because HTTP is a stateless protocol - so the connection between the server and the browser is lost once the request completes (typically a very short cycle).

If you need a page to be updated as soon as (or close enough to when) an event occurs, you need to use dynamic client-side scripting - e.g. JavaScript using the AJAX principles - and keep polling a servlet or other code on the server to determine when that event has fired. Once your JavaScript finds the right condition has occurred, it will then refresh your page or update its DOM accordingly.

Have I understood your question correctly?


Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
Bobby Sharma
Ranch Hand

Joined: Mar 18, 2008
Posts: 574
    
    1

Thanks Charles

Pradeep : why do you care to display the values on browser.If you are
preparing for exam then please don't bother because the exam does not go
that far.

but here is an example but it doesn't do what you want ,by the way.

//Dog class


//servlet



best regards,
omi

[ May 11, 2008: Message edited by: omi sharma ]
[ May 11, 2008: Message edited by: omi sharma ]
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
why do you care to display the values on browser.
It's a good point - there is very little reason to propagate (the results of) container events to the browser as they probably don't model exactly what behaviour you'd want. There might be educational value in it, but it won't be tested on the exam nor will you probably ever use it in production.

I guess you're thinking about something like session timeout (and subsequent destruction) as "logging a user out"? Probably easiest not to bother showing your users this though until they click on another page and find they've been logged out, as typically happens with online banking. Also if you're not careful the process of checking the status of a session using AJAX principles will in fact reset the timeouts so your user's session never times out while they have at least one page open - which could be useful for maintaining relatively current "user online" counters I suppose.
pradeep singh
Ranch Hand

Joined: Oct 23, 2007
Posts: 339
Hi
I am not asking this question for the exam point of view.I was asked this question in interview?
Paul Michael
Ranch Hand

Joined: Jul 02, 2001
Posts: 697
I agree with Charles, the first solution I can think of for these kind of problems is to use AJAX (for polling events) and have some nice JavaScript display the message for you once they are available.


SCJP 1.2 (89%), SCWCD 1.3 (94%), IBM 486 (90%), SCJA Beta (96%), SCEA (91% / 77%), SCEA 5 P1 (77%), SCBCD 5 (85%)
Bobby Sharma
Ranch Hand

Joined: Mar 18, 2008
Posts: 574
    
    1

Originally posted by pradeep singh:
Hi
I am not asking this question for the exam point of view.I was asked this question in interview?


Oh!,I see.By the way, some interviewers ask question which answer they
even don't know.

best regards,
omi
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how we can get notification of an event listener at web browser