• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Catch events in a servlet

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I have to write a servlet which must be integrated in a frame of an html page.
This servlet call methods of another class that may call some events.
I want to catch these event in the servlet because the html page must automatically change depending on the state.
How can i do this?
I try to resolv my problem setting the events in a variable of the class and reading that in the servlet. So I can change the page controlling this value and refreshing the html page periodically. but, is there another method to do that without refreshing?

Posts: 43016
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello "Kirk 'em all"-

Welcome to JavaRanch.

On your way in you may have missed that JavaRanch has a policy on display names, and yours does not comply with it - please adjust it accordingly, which you can do right here. Thanks for your prompt attention to this matter.

Enjoy your time here.
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You can create your own custom Exception classes and pass on the request, response objects to it.. so that it knows what to be sent back to the servlet as an error message.

Another way would be that all other classes will just throw the exceptions and it is caught at the servlet's doGet or doPost method.

(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think we need to be more precise about what happens on the server and what happens in the browser.

Most likely events are taking place on the server. If you'd like those to immediately show up on the browser you have to go outside normal HTTP protocols. This gets advanced in a hurry. My work system has an applet with an open ServerSocket so we can call out to it, but it's got problems to say the least.

A much easier approach is for the browser to occasionally ask the server for any updates. That's where you're talking about refreshing the page and you can surely avoid refreshing. You can have JavaScript on the browser call the HttpXMLService component to get data from the server every minute or whatever. Then the JavaScript updates inner HTML elements or somehow modifies the page. The user just sees the data change. They don't have to hit a key or see the whole page refresh.

If that sounds interesting we can dig into details. This architecture is called "AJAX" these days, but I'm afraid if you start Googling for AJAX you'll find a lot of confusing stuff that's way beyond your current problem.
CLUCK LIKE A CHICKEN! Now look at this tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic