java web 的最后一部分知识点
后面还会写一个贯穿案例OA系统
反正是用不了多久就该接触程序员的春天spring了小激动
Listener
作用
监听request,session,application三个域对象的创建,销毁数据的变更
使用
监听request对象
- 创建和销毁的监听:
实现
ServletRequestListener接口
重写
requestDestroyed(ServletRequestEvent servletRequestEvent)
requestInitialized(ServletRequestEvent servletRequestEvent)
参数
ServletRequestEvent servletRequestEvent 通过这个形参可以获取当前的request- 数据的变更监听:实现
ServletRequestAttributeListener接口
重写
attributeAdded(ServletRequestAttributeEvent servletRequestAttributeEvent)
attributeRemoved(ServletRequestAttributeEvent servletRequestAttributeEvent)
attributeReplaced(ServletRequestAttributeEvent servletRequestAttributeEvent)
参数
ServletRequestAttributeEvent servletRequestAttributeEvent 这个形参可以得到当前增加数据的键值
监听session对象
- 创建和销毁的监听:
实现
HttpSessionListener接口
重写
sessionCreated(HttpSessionEvent httpSessionEvent)
sessionDestroyed(HttpSessionEvent httpSessionEvent)
参数
HttpSessionEvent httpSessionEvent:可以获得当前的session创建对象- 数据的改变的监听:
实现
HttpSessionAttributeListener接口
重写
attributeAdded(HttpSessionBindingEvent httpSessionBindingEvent)
attributeRemoved(HttpSessionBindingEvent httpSessionBindingEvent
attributeReplaced(HttpSessionBindingEvent httpSessionBindingEvent)
参数
HttpSessionBindingEvent httpSessionBindingEvent获取当前监听的session
28/3/2020
昨天弄了一天的博客的反向代理,和https服务,申请了ssl证书,现在博客域名才算是真正的实装上了之前有点图有其表的感觉
应该会发一篇文章来写一下反向代理踩得坑
联网备案昨天初审也过了,明天去面审,过之后博客应该算是正式搭建完成了
美中不足的就是域名是个top为了省钱没买个com或者cn真是大亏
在项目中的web.xml中配置监听器,让监听器生效
<listener>
<listener-class>监听器的包名加类名</listener-class>
</listener>
Filter
过滤器:实质就是在服务器的servlet和浏览器的请求之间又加了一堵墙,用来过滤请求。
能处理的事物比如:权限问题,时限问题等等。。
使用
实现Filter接口重写方法
在web.xml中配置过滤器
<filter>
<filter-name>myfilter</filter-name>
<filter-class>com.yjb.filter.MyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>myfilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
过滤器的doFilter方法
作用:服务器接收到浏览器发过来的请求后,先创建request和response对象然后根据请求URL地址判断如果符合过滤器过滤规范,则会调用过滤器中的doFilter方法来进行拦截将req和resp作为实参传给doFilter方法
参数:
ServletRequest
ServletResponse
FilterChain:可以进行请求放行:chain.doFilter(request,response);
init方法和destroy方法
init:服务器启动时候调用
destory:服务器关闭时调用
证明:过滤器的声明周期位从服务器开启到服务器关闭
过滤器的拦截范围配置
拦截所有
/*
拦截部分
*.do
拦截指定
/my
和要拦截的制定的Servlet的url-pattern配置完全一致即可
注意:一个请求可能被多个过滤器拦截,只要它符合过滤器的范围。
写到这里javaweb就算是完结撒花了,基础知识方面我想着是继续向下进行,案例练习的话我也慢慢的跟着写就好了
恩,下一步就是大型框架的基础学习了,但是要到达春天中间还隔着一个mybatis要解决