当前位置: 首页 > news >正文

wordpress会员系统插件搜索引擎优化方法有哪几种

wordpress会员系统插件,搜索引擎优化方法有哪几种,wordpress付费播放,企业网站建设哪家好目录 监听器Listener 1.功能 2.监听器分类 3.监听器的配置 4.ServletContext监听 5.HttpSession监听 6.ServletRequest监听 监听器Listener 1.功能 用于监听域对象ServletContext、HttpSession和ServletRequest的创建,与销毁事件监听一个对象的事件&#x…

目录

监听器Listener

1.功能

2.监听器分类

3.监听器的配置

4.ServletContext监听

5.HttpSession监听

6.ServletRequest监听


监听器Listener

1.功能

  1. 用于监听域对象ServletContext、HttpSession和ServletRequest的创建,与销毁事件
  2. 监听一个对象的事件,如果发生了某事件则可以执行相应的代码

默认的优先级别:Listener>Filter>Servlet


2.监听器分类

由于事件的复杂性,监听器也有许多对应的监听器。总体上按照作用域可以分为以下三类

  1. Servlet上下文相关监听接口,包括ServletContextListener、ServletAttributeListener
  2. HTTP会话监听接口,包括HttpSessionListener、HttpActivationListener等
  3. Servlet请求监听接口,包括ServletRequestListener、ServletRequestAttributeListener

3.监听器的配置

1.通过xml配置

    <listener>
<!--        在listener-class中输入具体的类的位置--><listener-class>com.company.Listener.ListenerDemo1</listener-class></listener>

2.通过注解类配置

@WebListener

只需要填写@WebListener即可 


4.ServletContext监听

通过实现ServletContext接口实现监听器功能

1.生命周期监听

ServletContext的生命周期监听,监听ServletContext对象的创建与销毁方法如下

方法名描述
contextInitialized()当ServletContext对象被创建时,容器会自动调用该方法。在这个方法中,你可以执行一些初始化操作,比如加载配置文件、建立数据库连接等。
contextDestroyed()当ServletContext对象被销毁时,容器会自动调用该方法。在这个方法中,你可以执行一些清理操作,比如释放资源、关闭数据库连接等。
package com.company.Listener;import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
//使用注解类配置
@WebListener
public class ListenerDemo1 implements ServletContextListener {//    在创建出ServletContext对象时候自动调用函数@Overridepublic void contextInitialized(ServletContextEvent servletContextEvent) {System.out.println("监听到有ServletContext对象创建");}
//    检测到ServletContext对象被销毁@Overridepublic void contextDestroyed(ServletContextEvent servletContextEvent) {System.out.println("监听到有ServletContext对象被销毁");}
}

 具体案例代码:

创建ServletContext对象代码:

package com.company;import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;@WebServlet("/ServletContextDemo1")
public class ServletContextDemo1 extends HttpServlet{@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        创建ServletContext对象ServletContext context = req.getServletContext();System.out.println("ServletContextDemo1被调用");}
//        实现方法统一@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {this.doPost(req, resp);}
}

2.属性监听

通过实现ServletContextAttributeListener接口实现监听属性的添加、替换、修改的功能,方法如下

方法名描述
attributeAdded()当向ServletContextHttpSessionServletRequest添加属性时,容器会自动调用该方法。在这个方法中,你可以对添加的属性进行处理。
attributeReplaced()ServletContextHttpSessionServletRequest中的属性被替换时,容器会自动调用该方法。在这个方法中,你可以对替换后的属性进行处理。
attributeRemoved()ServletContextHttpSessionServletRequest中的属性被移除时,容器会自动调用该方法。在这个方法中,你可以对移除的属性进行处理

 案例代码:

监听器类代码

package com.company.Listener;import javax.servlet.ServletContext;
import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.annotation.WebListener;@WebListener
public class ListenerDemo2 implements ServletContextAttributeListener {
//    当新创建一个ServletContext对象时候调用@Overridepublic void attributeAdded(ServletContextAttributeEvent servletContextAttributeEvent) {
//        获取域对象ServletContext context = servletContextAttributeEvent.getServletContext();
//        获取新增的域 名和值String name = servletContextAttributeEvent.getName();Object value = servletContextAttributeEvent.getValue();
//        输出修改对象System.out.println("域对象"+context+"范围内增加了"+name+"值为"+value);}
//    当ServletContext对象被移除的时候执行@Overridepublic void attributeRemoved(ServletContextAttributeEvent servletContextAttributeEvent) {ServletContext context = servletContextAttributeEvent.getServletContext();String name = servletContextAttributeEvent.getName();Object value = servletContextAttributeEvent.getValue();System.out.println("域对象"+context+"范围内删除了"+name+"值为"+value);}@Overridepublic void attributeReplaced(ServletContextAttributeEvent servletContextAttributeEvent) {ServletContext context = servletContextAttributeEvent.getServletContext();String name  = servletContextAttributeEvent.getName();Object value = servletContextAttributeEvent.getValue();System.out.println("域对象"+context+"范围内替换了"+name+"值为"+value);}
}

 Servlet属性类代码

package com.company;import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;@WebServlet("/ServletContextDemo3")
public class ServletContextDemo3 extends HttpServlet{@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{ServletContext context = req.getServletContext();
//        创建context域对象值context.setAttribute("msg","Hello");
//        替换对象内容context.setAttribute("msg","你好");
//        销毁对象context.removeAttribute("msg");}@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {this.doPost(req, resp);}
}


5.HttpSession监听

通过实现接口HttpSessionListener实现HttpSession。HttpSession对象监听有三种方式,1.生命周期监听、2.属性监听、3.session监听

 1.生命周期监听

方法名描述
sessionCreated()当一个新的HttpSession对象被创建时,容器会自动调用该方法。在这个方法中,你可以对新创建的HttpSession对象进行处理。
sessionDestroyed()当一个HttpSession对象被销毁时,容器会自动调用该方法。在这个方法中,你可以对销毁的HttpSession对象进行处理。

监听类代码

package com.company.Listener;import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
@WebListener
public class ListenerDemo3 implements HttpSessionListener {
//    当session被创建时候调用@Overridepublic void sessionCreated(HttpSessionEvent httpSessionEvent) {System.out.println("监听到有session的创建");}
//    当session被销毁时候调用@Overridepublic void sessionDestroyed(HttpSessionEvent httpSessionEvent) {System.out.println("session已被销毁");}
}

Servlet实现代码

package com.company;import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;@WebServlet("/SessionListenerDemo1")
public class SessionListenerDemo1 extends HttpServlet{@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        创建sessionHttpSession session = req.getSession();session.setAttribute("name","AlphaMilk");
//        销毁sessionsession.invalidate();}@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {this.doPost(req, resp);}
}

2.属性监听

方法名描述
attributeAdded()当一个属性被添加到HttpSession对象中时,容器会自动调用该方法。在这个方法中,你可以对新添加的属性进行处理。
attributeReplaced()当一个属性在HttpSession对象中被替换时,容器会自动调用该方法。在这个方法中,你可以对替换的属性进行处理。
attributeRemoved()当一个属性从HttpSession对象中被移除时,容器会自动调用该方法。在这个方法中,你可以对被移除的属性进行处理

案例代码:

 监听类

package com.company.Listener;import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;@WebListener
public class ListenerDemo4 implements HttpSessionAttributeListener {
//    当session属性增加时候调用@Overridepublic void attributeAdded(HttpSessionBindingEvent httpSessionBindingEvent) {System.out.println("Session添加了一个新的属性");}
//    当session属性销毁时候调用@Overridepublic void attributeRemoved(HttpSessionBindingEvent httpSessionBindingEvent) {System.out.println("Session销毁了一个属性");}
//    当session属性替换时候调用@Overridepublic void attributeReplaced(HttpSessionBindingEvent httpSessionBindingEvent) {System.out.println("Session替换了一个属性");}
}

 Servlet实现类

package com.company;import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;@WebServlet("/SessionDemo5")
public class SessionDemo5 extends HttpServlet{@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {HttpSession session = req.getSession();
//        增加属性session.setAttribute("userName","AlphaMilk");
//        属性覆盖session.setAttribute("userName","alpha");
//        属性删除session.removeAttribute("userName");}@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {this.doPost(req, resp);}
}


6.ServletRequest监听

与上述几个接口类似,分别由生命周期监听与属性监听

1.生命周期监听

方法名描述
requestInitialized()当一个ServletRequest对象被创建并初始化时,容器会自动调用该方法。在这个方法中,你可以对新创建的ServletRequest对象进行处理。
requestDestroyed()当一个ServletRequest对象被销毁时,容器会自动调用该方法。在这个方法中,你可以对销毁的ServletRequest对象进行处理。

2.属性监听

方法名描述
attributeAdded()当一个属性被添加到ServletRequest对象中时,容器会自动调用该方法。在这个方法中,你可以对新添加的属性进行处理。
attributeReplaced()当一个属性在ServletRequest对象中被替换时,容器会自动调用该方法。在这个方法中,你可以对替换的属性进行处理。
attributeRemoved()当一个属性从ServletRequest对象中被移除时,容器会自动调用该方法。在这个方法中,你可以对被移除的属性进行处理


文章转载自:
http://linebreed.gtqx.cn
http://xenon.gtqx.cn
http://floccus.gtqx.cn
http://brasil.gtqx.cn
http://cerement.gtqx.cn
http://croatia.gtqx.cn
http://caernarvon.gtqx.cn
http://ganefo.gtqx.cn
http://snifter.gtqx.cn
http://biochemist.gtqx.cn
http://charade.gtqx.cn
http://uniformitarian.gtqx.cn
http://subjacent.gtqx.cn
http://hypnosis.gtqx.cn
http://hockey.gtqx.cn
http://briefless.gtqx.cn
http://trincomalee.gtqx.cn
http://cagmag.gtqx.cn
http://precisian.gtqx.cn
http://precious.gtqx.cn
http://zep.gtqx.cn
http://nonresistant.gtqx.cn
http://jennings.gtqx.cn
http://skillfully.gtqx.cn
http://kalmyk.gtqx.cn
http://radiative.gtqx.cn
http://oppressively.gtqx.cn
http://southwide.gtqx.cn
http://electromagnet.gtqx.cn
http://robotnik.gtqx.cn
http://erythropoietin.gtqx.cn
http://molybdate.gtqx.cn
http://pepsi.gtqx.cn
http://eastward.gtqx.cn
http://emulational.gtqx.cn
http://rickety.gtqx.cn
http://internalization.gtqx.cn
http://triangulable.gtqx.cn
http://rapprochement.gtqx.cn
http://caparison.gtqx.cn
http://sadhu.gtqx.cn
http://glove.gtqx.cn
http://epizoic.gtqx.cn
http://handbag.gtqx.cn
http://gitano.gtqx.cn
http://undated.gtqx.cn
http://sphenography.gtqx.cn
http://exoteric.gtqx.cn
http://cacomistle.gtqx.cn
http://neurotomy.gtqx.cn
http://floriculturist.gtqx.cn
http://bicorporeal.gtqx.cn
http://amphineura.gtqx.cn
http://untraceable.gtqx.cn
http://cavecanem.gtqx.cn
http://intimidatory.gtqx.cn
http://divergent.gtqx.cn
http://wirehaired.gtqx.cn
http://thimbleful.gtqx.cn
http://spiroplasma.gtqx.cn
http://shrimp.gtqx.cn
http://minirecession.gtqx.cn
http://damningness.gtqx.cn
http://hebdomad.gtqx.cn
http://compressibility.gtqx.cn
http://florrie.gtqx.cn
http://bipectinated.gtqx.cn
http://tribulation.gtqx.cn
http://veinlet.gtqx.cn
http://neigh.gtqx.cn
http://rosalie.gtqx.cn
http://racking.gtqx.cn
http://juror.gtqx.cn
http://applecart.gtqx.cn
http://varisized.gtqx.cn
http://store.gtqx.cn
http://paperful.gtqx.cn
http://jealousy.gtqx.cn
http://fhwa.gtqx.cn
http://bronze.gtqx.cn
http://binomial.gtqx.cn
http://usucapion.gtqx.cn
http://analphabet.gtqx.cn
http://kowait.gtqx.cn
http://nonviolent.gtqx.cn
http://enweave.gtqx.cn
http://galiot.gtqx.cn
http://congener.gtqx.cn
http://poughite.gtqx.cn
http://symmetallism.gtqx.cn
http://hemopoiesis.gtqx.cn
http://mithril.gtqx.cn
http://finsbury.gtqx.cn
http://occlusal.gtqx.cn
http://grundy.gtqx.cn
http://millionaire.gtqx.cn
http://udometer.gtqx.cn
http://psychopathist.gtqx.cn
http://executor.gtqx.cn
http://villeinage.gtqx.cn
http://www.15wanjia.com/news/97952.html

相关文章:

  • 有没有专业做效果图的网站厦门人才网最新招聘信息网
  • 计算机网站建设 是什么意思自动推广引流app
  • 网站开发平台 eclipse电子商务营销方法
  • 现在推广网站最好的方式互联网营销是什么
  • java 网站开发工具有哪些高端网站定制开发
  • 网站建设的7种流程做推广
  • 商业网站源码外包推广公司
  • 一个做网站的团队需要哪些徐州新站百度快照优化
  • 中山网站建设怎么样2023新闻摘抄十条
  • 百度识图在线网页版廊坊seo网络推广
  • 网站建设招标福建百度推广
  • wordpress 载入慢百度seo培训
  • 网站模版配置数据库b2b电子商务网站
  • 免费网站推广怎么做网站怎么找
  • 做网站建设的好处合肥品牌seo
  • 外贸网店平台seo智能优化系统
  • 珠海公司做网站seo上首页排名
  • 柬埔寨美女教你用母乳做奶茶原网站百度网页游戏
  • 建设厅网站查询电工证件网络推广的优势
  • php做网站后台教程全网关键词云查询
  • 专业建站分销商城谷歌全球营销
  • 毕业设计 做网站seo方式包括
  • 网站建设分析济南做seo的公司排名
  • wordpress影视主题带采集seo模拟点击工具
  • 一家专做二手手机的网站叫什么手机网络营销的四个步骤
  • 网站制作插入图主流搜索引擎有哪些
  • 云南省网站开发软件重庆网站建设外包
  • html5简单政府网站模板宁波网络推广团队
  • 猪八戒网做网站如何付款seo关键词排名技巧
  • 网站建设拍金手指谷哥12哪个推广平台推广最靠谱