File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Awkward question (sorry)

 
colin shuker
Ranch Hand
Posts: 750
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...)
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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


Whats the difference between refresh/reload ?
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- 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
Posts: 139
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Haha, I meant that Google Maps uses Ajax

There are a few links and explanations here :
AJAX
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1026
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Pie
Posts: 64186
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64186
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 750
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1026
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One last question.

Is AJAX a client side technology.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64186
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic