我做的聊天室想实现关键字的过滤功能 应该怎样实现呢 我用的是JSP写的代码
  下面是我的代码 帮我看一下应该放在哪里呀
<HTML>
<HEAD>
<%@ page 
language="java"
contentType="text/html; charset=GB2312"
pageEncoding="GB2312"
%>
<META http-equiv="Content-Type" content="text/html; charset=GB2312">
<%@page import="java.util.*"%>
<link rel="stylesheet" href="chat.css">
<script language="JavaScript" type="">function checkForm() {
if (document.chatForm.usermessage.value == "") {
alert("发言不能为空!");
document.chatForm.usermessage.focus();
return false;
}
else {
document.chatForm.usermessage.focus();
return true;
}
}function userLogout() {
top.window.location="login.jsp?logout=yes";
}function openWindow(url) {
var newWin = window.open(url,"","toolbar=no,status=no,scrollbars=yes,menubar=no,width=450,height=320");
return false;
}
</script></HEAD>
<BODY bgcolor="#FF9900" >
<FORM name="chatForm"  method="post" action="input.jsp">
<table border="0" width="100%" align="center" cellspacing="0" cellpadding="0">
<tr valign="top"><td>
<%
request.setCharacterEncoding("gb2312");
String first = (String)request.getParameter("first");
String talkMessage=(String)request.getParameter("usermessage");
String action = (String)request.getParameter("action");
String fontcolor = (String) request.getParameter("fontcolor");
String talkwith =(String)request.getParameter("talkwith");
String systemSpeak=(String) request.getParameter("systemSpeak");//用户等级资料
String experience = (String)session.getAttribute("experience");
if (experience == null)
{
   experience = "0";
}
/*
if (userlevel == null)
{
     userlevel = "过客";
}
*/
String Name=(String)session.getAttribute("username");session.setAttribute("sName",Name);
out.println("【<font color='#0000ff'>"+Name+"</font>】"+"对");//用户第一次进入,初始化状态
if (first == null) {
talkMessage="系统公告:<font color = blue>"+Name+"</font>进入了聊天室,大家欢迎!";
action = "no";
fontcolor = "#000000";
systemSpeak = "yes";
}if(talkwith==null) {
 talkwith = "所有人";
}%>
        <input type="text" name="talkwith" value= <%= talkwith %> size="8" style="font-size:9pt">
        动作
        <select name="action" size="1" style="font-size:9pt">
          <option value="no" selected>说话</option>
          <option value="友好地拉着B的手说:">问好</option>
          <option value="向B会意地点点头,说:">点头</option>
          <option value="对B妩媚地甜甜一笑,说:">妩媚</option>
          <option value="万事不萦于心地呵呵笑着对B说:">开朗</option>
          <option value="一脸的坏笑,不怀好意地打量着B,说:">坏笑</option>
          <option value="忍住泪水,强挤出一丝笑容对B说:">苦笑</option>
          <option value="白了B一眼,十分不屑地说:">白眼</option>
          <option value="轻轻地在B的额头上吻了一下,温柔地说:">轻吻</option>
          <option value="热烈地拥抱着B,几乎透不过气来,说:">拥抱</option>
          <option value="含情脉脉地凝视着B说:">深情</option>
          <option value="泪珠儿在眼眶里打转,无限伤心地对B说:">伤心</option>
          <option value="羞红了脸,拧过身子背对着B说:">害羞</option>
          <option value="气得全身发抖,两眼喷火瞪着B,说:">愤怒</option>
          <option value="向B招招手,中间夹了个飞吻,说:">招手</option>
          <option value="嘟着嘴哼哼哧哧地对B说:">不满</option>
          <option value="兴奋得不得了,对着B翩翩起舞,说:">兴奋</option>
          <option value="情不自禁地搂着B热吻起来,还叽哩咕噜地说:">狂吻</option>
          <option value="泪光闪闪看着B,脸上写满了委屈的说:">委屈</option>
          <option value="急得直跺脚,气急败坏地对B说:">着急</option>
          <option value="泪如泉涌,对着B哗啦哗啦哭了起来,说:">嚎啕</option>
          <option value="皱起眉头别转脸,却又偷看B一眼,故作生气说:">撒娇</option>
          <option value="眯起斗鸡眼看着B一阵奸笑说:">奸笑</option>
          <option value="突然跃起飞脚猛踢B屁股,说:">飞脚</option>
          <option value="左右开弓抽得B满地找牙,说:">抽掴</option>
          <option value="冲B皮笑肉不笑地说:">假笑</option>
        </select>
        <input type="hidden" name="first" value="first">
        <input type="hidden" name="systemSpeak" value="no">
<%
String aloneTalk=request.getParameter("alonetalk");
if(aloneTalk==null)
aloneTalk="no";
if(aloneTalk.equals("no"))
out.print("<input type=\"checkbox\" name=\"alonetalk\" value=\"yes\" > 悄悄话 ");
else
out.print("<input type=\"checkbox\" name=\"alonetalk\" value=\"yes\" checked > 悄悄话");
%>  <a href="chathelp.htm" onclick="return openWindow(this.href);">聊天帮助</a> <a href="advanced.jsp" onclick="return openWindow(this.href);">高级功能</a><br>
       
       
        <input type="submit" name="Submit" value="发送" style="font-size:9pt" onclick="return checkForm();">
        <input type="button" name="logout" value="离开" style="font-size:9pt" onclick="return userLogout();">        </td>      <td>
<table width="200" border="0" cellspacing="0" cellpadding="0" align="right"  bgcolor="#FF9900" >
<tr> </tr>
<tr>
<td colspan="3" height="71" bgcolor="#FEEE94" valign="middle" align="center">
<table width="91%" border="0" cellspacing="0" cellpadding="0">
<tr align="center" valign="middle">
<td colspan="3">
功力值: <font color="#FF3300"><%= experience %></font> 分 </td>
</tr>
<tr align="center" valign="middle">
<td width="32%"><a href="null.htm">会员注册 </a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="3" height="10" bgcolor="#E86A1B"><img src="../images/spacer.gif" width="1" height="10" alt=""></td>
</tr>
</table>
      </td>    </tr>
  </table>
<%
String action2 = "";
int i = action.indexOf("B");
if (i != -1) {
action = action.substring(0,i) + "<font color='blue'>" + talkwith + "</font>" + action.substring(i+1);
}if(!action.equals("no")) {
talkMessage = action + "<font color=" + fontcolor + ">" + talkMessage + "</font>";
action2 = "yes";
}else if (first != null) {
talkMessage = "<font color = " + fontcolor + ">" + talkMessage + "</font>";
action2 = "no";
}
String online = (String) session.getAttribute("online");
if (online == null) {
online = "";
}
if (online.equals("no")) {
out.print("<script>alert(\"你已经被踢出,不要再捣乱啦!\");</script>");
return;
}if (Name == null) {
return;
}Vector  Message = null;
synchronized (application) {
Message= (Vector)application.getAttribute("Message");
if(Message==null) {
Message= new Vector(30,10);
}
if(Message.size()>200) {
Message.removeAllElements();
} Message.addElement(aloneTalk);
Message.addElement(Name);
Message.addElement(talkwith);
System.err.println("2"+talkwith);
Message.addElement(talkMessage);
Message.addElement(systemSpeak);
Message.addElement(action2);
application.setAttribute("Message", Message);

}
%>
</FORM>
</BODY>
</HTML>