I did it right, I think.

I'm trying to develop dynamic chatroom application for my JUG in Bandung using combo : 
JSP, applet, servlet, and bean.

First, user enter chatroomguide.jsp : there he will be presented with open chatrooms 
(complete with relevant info like number participants in each chat room). He can join 
or he can create a new chat room for discussing different topic.

My chatroomguide.jsp instantiate application scope object, which is a bean, of type 
ChatroomHubBean.

ChatroomHubBean run on its own thread (call it janitor) that periodically checks 
number of participant in each room.
Those Chatroom objects are stored in a hashtable, chatroompool. If number of 
participant = 0, janitor will remove that chatroom from the pool.

Now, user click join or create a chatroom. His browser will load ChatroomApplet, which 
will spawn 2 threads on the client machine, checkLatestSpeeches, 
checkRoomParticipant...

Those threads will periodically communicate with ChatroomHubServlet to fetch 
latestspeeches & participant using HTTP GET message. Along with the message is a 
chatroomid parameter and action parameter whose value may be : "getlatestspeeches", 
"getparticipantlist", or "postspeech"

ChatroomHubServlet, upon receiving a HTTP message, will try to locate that particular 
instance of ChatroomHubBean, which I expect is available in servlet context. Then, the 
appropriate method in ChatroomHubBean will be invoked by ChatroomServlet, which in 
turn will invoke appropriate method in appropriate Chatroom object.

I have to user another servlet here (that ChatroomHubServlet), since applet and the 
web application need to communicates object, not just texts.

The problem is : The servlet can't obtain the bean.
Why ? I'm sure they're in the same context.
the jsp is "ran" by GnuJSP which I set to be in jugb zone. And I also put the servlet 
in jugb zone. (I'm using JServ and GnuJSP). No, I'm not using JSDK2.1. So there is no 
such servletContext.setAttribute(string,Object). I only have getAttribute(String) 
which I can call from the servlet to obtain the bean.

In my chatroomguide.jsp :
<jsp:useBean id="chatroomHub" scope="application" ...>
  <% ... %>
</jsp:useBean>

In my ChatroomHubServlet from doGet and doPost:
ChatroomHubBean chub = 
(ChatroomHubBean)getServletContext().getAttribute("chatroomHub");
...
chuc.putSpeech(chatroomId, speech, session.getValue(userEmail), 
session.getValue(userName));
...
(Each chatroom maintains a circular buffer to hold the "voices" of the talkers. When 
the talker send HTTP GET with paramater acrtion=getlatestspeeches, he will get an 
array of strings which is a fragment if circular buffer). I don't use any RMI here.

I'm sure that my jsp and my servklet reside in the same context. I've printed the 
session id from within both of them.

I get NullPointerException on the server. chub == null.

Huh ?!

Please give me an advice ho to solve this. Where is my fault ?

Thanks...very...very much

Regards from Bandung
-raka-


Send FREE Greetings for Father's Day--or any day!
Click here: http://www.whowhere.lycos.com/redirects/fathers_day.rdct

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to