简易聊天室

<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<html>
<head>
<title>聊天室</title>

</head>
<body onload="scroll(0,99999)">
    <%
        //设置乱码
        request.setCharacterEncoding("gbk");
        //取得发送的聊天信息
        String message = request.getParameter("message");

        String msg = (String) application.getAttribute("msg");
        //如果取不到,说明是第一次,直接把得到的信息放入容器中即可。
        if (message != null) {
            if (msg == null) {
                //向这个容器中装入数据
                application.setAttribute("msg", message);
            } else {
                msg = msg + "<br>" + message;
                application.setAttribute("msg", msg);
            }
        }
        out.println(msg);
    %>

    <form method="post" action="" name="form">
        <hr color="green" />

        <br> &nbsp;&nbsp;&nbsp;&nbsp; 欢迎进入聊天室 <br> <br> <br>
        请说话: <br> &nbsp;&nbsp;
        <textarea cols="35" rows="6" name="message"></textarea>
        <input type="submit" value="提交" name="button">
    </form>

</body>
</html>

posted on 2013-10-11 16:58  @冰糖  阅读(186)  评论(0编辑  收藏  举报

导航