Ajax Chat Room (JSP edition) 5__jsp

Source: Internet
Author: User
Tags log log ajax chat

Java class used, in addition to the above several, there are several left.

Two filter classes, one for filtering characters, and one for filtering users who are not logged in.

PackageOrg.jvk.chatroom.filter;ImportJava.io.IOException;ImportJavax.servlet.Filter;ImportJavax.servlet.FilterChain;ImportJavax.servlet.FilterConfig;ImportJavax.servlet.ServletException;ImportJavax.servlet.ServletRequest;ImportJavax.servlet.ServletResponse;ImportJavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse;ImportJavax.servlet.http.HttpSession;ImportOrg.jvk.chatroom.servlet.BaseServlet; Public classChatroomfilterImplementsFilter {Private Static FinalString login_page = "/chatroom";Private Static FinalString USER = Baseservlet. USER; Public voidDofilter (ServletRequest request, servletresponse response, Filterchain chain)throwsIOException, servletexception {httpservletrequest req = (httpservletrequest) request; HttpSession session = Req.getsession (false);if(Session = =NULL|| Session.getattribute (USER) = =NULL) {((HttpServletResponse) response). Sendredirect (Login_page); return;     Chain.dofilter (request, response); } Public voidInit (Filterconfig filterconfig)throwsServletexception {} Public voidDestroy () {}}

PackageOrg.jvk.chatroom.filter;ImportJava.io.IOException;ImportJavax.servlet.Filter;ImportJavax.servlet.FilterChain;ImportJavax.servlet.FilterConfig;ImportJavax.servlet.ServletException;ImportJavax.servlet.ServletRequest;ImportJavax.servlet.ServletResponse; Public classCharacterencodingImplementsFilter {protectedString encoding =NULL;protectedFilterconfig Filterconfig =NULL;protected BooleanIgnore =true; Public voidDestroy () { This. encoding =NULL; This. Filterconfig =NULL; } Public voidDofilter (ServletRequest request, servletresponse response, Filterchain chain)throwsIOException, Servletexception {if(Ignore | | (request.getcharacterencoding () = =NULL) {String encoding = selectencoding (request);if(Encoding!=NULL) request.setcharacterencoding (encoding);       Chain.dofilter (request, response); } Public voidInit (Filterconfig filterconfig)throwsservletexception { This. Filterconfig = Filterconfig; This.        encoding = Filterconfig.getinitparameter ("encoding"); String value = filterconfig.getinitparameter ("Ignore");if(Value = =NULL) This. Ignore =true;Else if(Value.equalsignorecase ("true") | | | value.equalsignorecase ("yes") This. Ignore =true;Else This. Ignore =false; }protectedString selectencoding (ServletRequest request) { return( This.       encoding); A listener is used to initialize the chat room (call the Chatroommanager config method).PackageOrg.jvk.chatroom.listener;ImportJava.io.File;ImportJava.io.IOException;ImportJavax.servlet.ServletContextEvent;ImportJavax.servlet.ServletContextListener;ImportOrg.apache.commons.logging.Log;ImportOrg.apache.commons.logging.LogFactory;ImportOrg.jvk.chatroom.service.ChatroomManager; Public classInitchatroomImplementsServletcontextlistener {Private StaticLog log = Logfactory.getlog (initchatroom.class); Public voidContextinitialized (Servletcontextevent event) {String configfile = Event.getservletcontext (). Getinitparameter ("Co Nfigfile ");Try{chatroommanager.newinstance (). config (NewFile (Event.getservletcontext (). Getrealpath (ConfigFile))); }Catch(IOException e) {log. Error (e);Throw NewRuntimeException (E.getmessage ()); }     } Public void Contextdestroyed (Servletcontextevent event) {   }} at this point, all Java class code is gone. Below begins to write the client's JS code and interface HTML code. By the way, post the configuration file as well. <?xml version= "1.0" encoding= "GBK"?> <project name= "ajax chat Room" default= "Default" basedir= "E:/jsp/chatroom" ;     <!--set path properties   -->     <property environment= "env"/>  & nbsp;  <!--    <property file= "build.properties"/>    -->      <property name= "Tomcat.home" value= "g:/greensoftware/tomcat-6.0.10"/>     < Property Name= "Source.root" value= "${basedir}/src"/>    

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.