2004IBMSoftwareInstituteWSADWEBListener+Filter)2IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstituteWindows2000SP3WindowsXPWebSphereStudioApplicationDeveloperv5DB2Version8.13IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstitute786MRAM(1G)1.7G+4IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstitute99999Request995IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstitute9996IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstitute9Web9Servlet9Servlet7IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstituteServlet2.49ServletContextAttributeListener9ServletContextListener9ServletRequestAttributeListener9ServletRequestListener9HttpSessionActivationListener9HttpSessionAttributeListener9HttpSessionBindingListener9HttpSessionListener8IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstitutesessionsessionsessionsession9IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstituteOnLineCounterListenerStp1eshopJavaSourceÆStp2com.webshop.listenerOnLineCounterListenerHTTP10IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstituteOnLineCounterListenerStp3WSADOnLineCounterListener11IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstituteOnLineCounterListenerpackagecom.webshop.listener;importjavax.servlet.http.*;importjavax.servlet.*;publicclassOnLineCounterListenerimplementsHttpSessionListener{privateintcount;//privateServletContextcontext=null;//ServletpublicOnLineCounterListener(){count=0;}//sessionpublicvoidsessionCreated(HttpSessionEventse){count++;//1setContext(se);}//sessionpublicvoidsessionDestroyed(HttpSessionEventse){count--;//1setContext(se);}12IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstituteOnLineCounterListenerServletContextServletContextonLine//contextattributeReplacedattributeAddedpublicvoidsetContext(HttpSessionEventse){if(context==null)context=se.getSession().getServletContext();context.setAttribute(“onLine”,newInteger(count));//Servlet}13IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstituteJSPOnLineCounterListenerServletContextonLineJSPbottom.jspfpalign=centerahref==/images/poweredby.pngborder=0width=160height=98/abr/pcenter%=getServletContext().getAttribute(onLine)==null?0:getServletContext().getAttribute(onLine)%/center/body/html14IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstitute15IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstituteWebJSPServlet16IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstituteWeb17IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstituteStp1javax.servlet.FilterStp2web.xmlStp3web.xml18IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstituteStp1eshopJavaSourceÆ19IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstituteStp2com.webshop.filterEncodingFilter20IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstituteRequestStp3encodinggb2312URL“/*”URL21IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstituteEncodingFilterpackagecom.webshop.filter;importjavax.servlet.FilterChain;importjavax.servlet.ServletRequest;importjavax.servlet.ServletResponse;importjava.io.IOException;importjavax.servlet.Filter;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importjavax.servlet.ServletException;importjavax.servlet.FilterConfig;publicclassEncodingFilterimplementsFilter{protectedFilterConfigfilterConfig;privateStringtargetEncoding=gb2312;/***,Servlet*/publicvoidinit(FilterConfigconfig)throwsServletException{this.filterConfig=config;this.targetEncoding=config.getInitParameter(“encoding”);//}22IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstituteEncodingFilter/****/publicvoiddoFilter(ServletRequestsrequest,ServletResponsesresponse,FilterChainchain)throwsIOException,ServletException{HttpServletRequestrequest=(HttpServletRequest)srequest;request.setCharacterEncoding(targetEncoding);//chain.doFilter(srequest,sresponse);}publicvoidsetFilterConfig(finalFilterConfigfilterConfig){this.filterConfig=filterConfig;}//publicvoiddestroy(){this.filterConfig=null;}23IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstituteWSADweb.xml24IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstituteWebJSPStrutsAction99JSP25IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstituteSignonFilterpublicvoiddoFilter(ServletRequestreq,ServletResponseresp,FilterChainchain)throwsServletException,IOException{HttpServletRequestrequest=(HttpServletRequest)req;HttpServletResponseresponse=(HttpServletResponse)resp;AccountFormacctForm=(AccountForm)request.getSession().getAttribute(accountForm);CartFormcartForm=(CartForm)request.getSession().getAttribute(cartForm);//acctFormacctForm.getAccount()if(acctForm==null||acctForm.getAccount()==null){request.setAttribute(targetPage,request.getRequestURI());//response.sendRedirect(LOGIN_PAGE);}else{chain.doFilter(req,resp);//}}26IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstituteSignonFilterSignonFilterURLURLweb.xmlSignonFilterURLURL27IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstitute1SignonFilter2EncodingFilterÆÆÆÆ28IBMSoftwareInstituteWSADWEB2004IBMSoftwareInstituteWebServletServletWebJSPServlet