Creating the Chat HTML Page


There are two parts to this applicationthe part that reads new comments from the user, and the part that displays the current comments every 5 seconds in the upper half of the screen. To keep those two parts separate, Chat uses HTML frames. The top frame, where everyone's comments appear, is given 65% of the vertical space, and the bottom frame, where the user enters his own comments, is given 35%. Also, the frames are borderless, which gives users the impression that the result is all a single, seamless page:

 <HTML>     <HEAD>         <TITLE>Chat</TITLE>     </HEAD>     <FRAMESET ROWS="65%, 35%" FRAMEBORDER='0' FRAMESPACING='0'>         .         .         .     </FRAMESET> </HTML> 

Although not very likely, some users may be using older browsers that don't support frames, so it's customary to display a message, using the <NOFRAMES> HTML element, telling them they need a browser that supports frames:

 <HTML>     <HEAD>         <TITLE>Chat</TITLE>     </HEAD>     <FRAMESET ROWS="65%, 35%" FRAMEBORDER='0' FRAMESPACING='0'>         <NOFRAMES>Sorry, you need frames to use chat.</NOFRAMES>         .         .         .     </FRAMESET> </HTML> 

Because both the top and bottom frames need to share the text data sent in by the user, they're both handled by the same JSP file, chat.jsp:

 <HTML>     <HEAD>         <TITLE>Chat</TITLE>     </HEAD>     <FRAMESET ROWS="65%, 35%" FRAMEBORDER='0' FRAMESPACING='0'>         <NOFRAMES>Sorry, you need frames to use chat.</NOFRAMES>         <FRAME NAME="_display" src="/books/1/263/1/html/2/chat.jsp">         <FRAME NAME="_data" src="/books/1/263/1/html/2/chat.jsp">     </FRAMESET> </HTML> 

However, chat.jsp should have some way of knowing which half of the display it's dealing withthe upper half (where the current comments are displayed) or the lower half (where the user enters comments). To give chat.jsp a hint about what it should be doing, chat.html passes a little extra data when it fetches the top frame from chat.jsp. It does that with a process called URL encoding, which is used when passing data from HTML forms to JSP files or other files on a web server. In this case, it passes a parameter named t, setting that parameter's value to "1":

 <HTML>     <HEAD>         <TITLE>Chat</TITLE>     </HEAD>     <FRAMESET ROWS="65%, 35%" FRAMEBORDER='0' FRAMESPACING='0'>         <NOFRAMES>Sorry, you need frames to use chat.</NOFRAMES>         <FRAME NAME="_display" src="/books/1/263/1/html/2/chat.jsp?t=1">         <FRAME NAME="_data" src="/books/1/263/1/html/2/chat.jsp">     </FRAMESET> </HTML> 

This is the way data can be sent from controls such as text fields back to JSP pages. Now chat.jsp will be able to check for that parameter (t), and if it equals "1", chat.jsp knows it's dealing with the top half of the page, so it should display the current comments.

That's all you need for chat.html; now it's time to start working on chat.jsp.



    Java After Hours(c) 10 Projects You'll Never Do at Work
    Java After Hours: 10 Projects Youll Never Do at Work
    ISBN: 0672327473
    EAN: 2147483647
    Year: 2006
    Pages: 128

    Similar book on Amazon

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net