File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Awkward question (sorry) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Awkward question (sorry)" Watch "Awkward question (sorry)" New topic
Author

Awkward question (sorry)

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Hi, I am making a two player connect 4 game.
The way it currently works is that when 2 people are accesing
the site on different computers, they each have a jsp page in front
of them showing the board and the counters.
When one player plays a move, his jsp page is updated straight away,
but the other player won't see the previous players move, till they
make a move.
This is why I have got the jsp page to refresh itself every 5 seconds.
And so now, playing the game is realistic as each player sees, the other
players move.
But I don't like the way the screen keeps flashing every 5 seconds.
It's really offputting, I am curious to know if I can perhaps use the
ServletContext AttributeListener (<-- 1 word, but javaranch doesnt like long words)
I suppose I would need to be using servlets instead of jsps.
But the problem here is that the attributeReplaced(...) method
won't allow me to use dis.forward(req,res), since req and res are not
arguments of the method, nor are they class variables.

I would really appreciate any help with this, as it would make my program
really good.
Thanks very much for any help
[ December 28, 2005: Message edited by: Bear Bibeault ]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

I'm not sure that Servlet/JSP is appropriate for this kind of thing.
You need to refresh the content of the page without reloading the page.
Ajax might be a better choice (but I don't know if the two player thing would be possible...)


[My Blog]
All roads lead to JavaRanch
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026

You need to refresh the content of the page without reloading the page.


Whats the difference between refresh/reload ?


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

- Reloading a page will make it to go blank, and then the content will be displayed (causing the annoying flickering Colin is talking about)

- By 'Refreshing the content', I mean changing the content of a portion of the page, without reloading it from the start.

Using DHTML, you can change the content of a page dynamically.
Have a look at Google Maps.
Mahesh Rana
Ranch Hand

Joined: Sep 05, 2001
Posts: 139
AJAX is the new breed of Java script / XML, which has made the flickering problem a history.
And most of the HTTP browsers support it.


SCJP2
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
Nice explanation Satou kurinosuke. All these days I was under the impression that both are same.


By 'Refreshing the content', I mean changing the content of a portion of the page, without reloading it from the start.


Is it something like the ads in Yahoo Inboxes. Which keeps changing dynamically once in a while when rest of the page is static.


Have a look at Google Maps.


Yes I did. It takes time to load and only parts of the page is loading at a time causing the rest of the page look blank. Its really annoying.


AJAX is the new breed of Java script / XML, which has made the flickering problem a history.


Can you guys give a site that uses AJAX which refreshes the page without reloading.
[ December 28, 2005: Message edited by: Vishnu Prakash ]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Haha, I meant that Google Maps uses Ajax

There are a few links and explanations here :
AJAX
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026

Haha, I meant that Google Maps uses Ajax


Then why its taking time to load when I zoom-In.

OK. Tell me a site that doesn't use AJAX and makes the browsing experience hostile by loading the page for a long duration.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

The content of the map takes time to refresh (this still needs heavy processing to display such information),
but you may notice that the entire pages does not change (the part around the map).

For a user-unfriendly page, I can't tell a site straight away.
I would say a lamely coded ASP page
[ December 28, 2005: Message edited by: Satou kurinosuke ]
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026

The content of the map takes time to refresh (this still needs heavy processing to display such information),
but you may notice that the entire pages does not change (the part around the map).


Yes this time I noticed it correctly. Only the Map in that web page is refreshing and NOT the entire page.

asynchronous data retrieval using XMLHttpRequest;
XMLHttpRequest enables JavaScript to make HTTP requests to a remote server without the need to reload the page. In essence, HTTP requests can be made and responses received, completely in the background and without the user experiencing any visual interruptions.

One more question which is the correct forum to discuss about AJAX.

Thanks for the link.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61601
    
  67

Originally posted by Vishnu Prakash:
Can you guys give a site that uses AJAX which refreshes the page without reloading.


A game I wrote using Ajax: http://www.bibeault.org/blackbox

One more question which is the correct forum to discuss about AJAX.


The HTML/Javascript forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

http://maps.google.com is another.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Ajax helps with the clean refresh problem, but doesn't help player2 know that player1 has just made a move. Applets might be a better technology as they can open sockets and do a little behind the sceens P2P or IM type thing to send new plays to each other. You could even have an applet with no GUI that tells the page when to refresh the game board via Ajax. Any of that sound interesting?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61601
    
  67

Stan brings up a good point. Because they are based on HTTP, web applications are not a friendly environment for real-time activities. You are going to have to do some weird and unconventional things to get this to work.

So if you are using this project to try and learn web application technologies (as I believe you have alluded in other posts), your choice of project could have been better.
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Yes, perhaps I could have chosen another project, but it all helps towards
learning what you can and can't do.
I'm considering a 1 player connect 4 game, when you play against the
computer.
I suppose this could actually be done as a applet, but I want to try it
with jsp's/servlets.
For the 1 player connect4 game, I would use negamax with alpha-beta
pruning, but I need to work out how to build the static evaluation function
first.

I'm trying to think of other web applications I can make that let 2
(or more) users interact in some way, like with the 2 player connect 4 game.

Although this 'not being able to reload page when required' issue
is going to be a problem with many types of web applications,
especially games.

Any good ideas for web applications would be kindly appreciated.
Thanks very much
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
One last question.

Is AJAX a client side technology.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61601
    
  67

Yes. Ajax is a client-side mechanism that allows you to make "back-door" requests to the server side without having to reload the page.
Sandip Chaudhuri
Greenhorn

Joined: Dec 27, 2004
Posts: 26
hi were u able to solve the problem ??

anyway i have a method which might help.

First javascript will be necessay.
when a user makes a move his page gets submitted.
when it reload it is in disabled stare.

however using remote scripting (AJAX preferably but u can use anything else as well) it requests the server for knowledge weather the other user has made his move.

if the other user has made his move then u can either relaod the page or refresh it using remote scripting. (i would prefer reloading though, depending upon the complexity of the game the new positions might require a lot of scripting i guess)

the page will now be in enabled mode waiting for this user to submit his move.

the submittion of the page will be through javascript. when a user has made a move.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Awkward question (sorry)