This is my first post, although not the first time viewing, on this website. I have a question about JSP pages that I cannot understand. I am currently working on a Connect 4 project where I need to have two users connect to the same webpage with the game on it. The first page a user encounters is a "login" page asking for a name and once they submit the name they are taken to the page with the game.
My question is how would I go about connecting two different browser windows to this game? (For testing) I know that a JavaBean would be one way to do it but I have never created one and am completely lost as to how to do it. Any help would be necessary and I can provide the code I have upon request.
Are you a newbie to Servlets and JSP? If so, this might be too ambitious for a first outing.
If not, then you know that each user will have their own session. So you'd need to keep track of the various games (I assume you want to have more than just one game going at a time) in application scope.
I am fairly new to servlets but I do not have a choice, this is for a project that I have to do for a course I am taking. I am completely lost on how to implement a JavaBean, I know that it must be in application scope. How would I go about actually putting it in the code and having it run with multiple users?
Yikes -- way too complex an assignment for an intro course, in my opinion.
In any case, create a class or classes to abstract the state of the game. That's rather independent of servlets or JSP. Once you have classes that work to capture the game, you can store it (them) in app scope so that both users have access to it.
Bear Bibeault wrote:Yikes -- way too complex an assignment for an intro course, in my opinion.
How would I go about storing the game in application scope? I'm sorry, but I am extremely new to the concept of servlets, JSPs, JavaBeans and everything. All that I have ever done is some minor work in Java but nothing to this extent and nothing on the web.
I am pretty new to JSP pages and I was wondering how to get two browsers on my computer to connect to the same page and see each other.
I have a login page set up, so both browsers would access that login page first, then login with unique usernames and then once they login I want to post-login page to refresh so that all the users that are accessing that page are visible.
It all goes back to the same concept: the data needs to be stored somewhere where the entire application has access to. For run-time information (most appropriate for a game), that would be application scope. For most other non game (e.g. business) uses, a database is frequently used.
Can't think of any off the top of my head. Most business applications will not share information in this manner. In fact, they rather go out of their way to make sure that data is not shared between sessions.
But it's really not all that complicated. Anything you put into app scope is accessible to all of the application. The ServletContext's setAttribute() and getAttribute() methods are the access methods.
The only tricky thing to be careful of is synchronization for read-write data.
I don't know why I'm having the hardest time ever understanding this concept.
Currently I have a index jsp page where the user is asked to type in the name and click submit. Once that is submitted it is sent to a servlet that grabs the name submitted and prints it out on the screen. Where does the bean come in to all of this and how would I then pass the name from the servlet to the bean? Or would I pass the name straight from the index to the bean?
The problem is that you are trying to do something rather advanced before understand the very basics of web application technology.
You keep mentioning "the bean". Have you defined "the bean" and what it represents? As I said earlier, worrying about the mechanics is premature before you have decided how you are going to abstract the data that you need to maintain to represent the model of the game. Have you done that?