servlet属性值的改变;

网友投稿 655 2022-10-08

servlet属性值的改变;

servlet属性值的改变;

1.新建一个Demo4代码如下:

package com.ask.listener; import javax.servlet.ServletContextAttributeEvent; import javax.servlet.ServletContextAttributeListener; //servlet属性值的改变; public class Demo4 implements ServletContextAttributeListener { //增加 public void attributeAdded(ServletContextAttributeEvent scab) { System.out.println("attributeAdded"); System.out.println(scab.getName()+" "+scab.getValue()); } //移除 public void attributeRemoved(ServletContextAttributeEvent scab) { System.out.println("attributeRemoved"); System.out.println(scab.getName()+ " "+scab.getValue()); } //取代; public void attributeReplaced(ServletContextAttributeEvent scab) { System.out.println("attributeReplaced"); System.out.println(scab.getName()+" "+scab.getValue()); } }

2.新建一个index.jsp增加代码如下:

<% application.setAttribute("name", "tom"); application.setAttribute("sal", "6000"); application.removeAttribute("sal"); %>

3.web.xml配置文件代码如下:

com.ask.listener.Demo4

4.程序运行如下:

attributeReplaced name tom attributeAdded sal 6000 attributeRemoved sal 6000

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:miniapps小程序项目脚手架工具(小程序脚手架搭建)
下一篇:filter过滤器登录验证
相关文章

 发表评论

暂时没有评论,来抢沙发吧~