1,Servlet过滤器

 <filter>
<filter-name>charset</filter-name>
<filter-class>org.guangsoft.filter.CharsetFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter> <filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> Filter:
package org.guangsoft.filter; public class CharsetFilter implements Filter
{
private String encoding;
public void init(FilterConfig filterconfig) throws ServletException
{
this.encoding = filterconfig.getInitParameter("endcoding");
}
public void doFilter(ServletRequest req, ServletResponse resp,
FilterChain chain) throws IOException, ServletException
{
req.setCharacterEncoding(encoding);
chain.doFilter(req, resp);
}
public void destroy()
{
}
}

2,Servlet监听器

Web.xml:
<listener>
<listener-class>org.guangsoft.listener.CountListener</listener-class>
</listener>
Listener:
public class CountListener implements HttpSessionListener
{
private ServletContext sc = null;
public void sessionCreated(HttpSessionEvent se)
  {
this.sc = se.getSession().getServletContext();
Integer i = (Integer) this.sc.getAttribute("online");
if (i == null)
i = new Integer(0);
i = new Integer((i.intValue()) + 1);
this.sc.setAttribute("online", i);
}
public void sessionDestroyed(HttpSessionEvent httpsessionevent)
  {
Integer i = (Integer) this.sc.getAttribute("online");
if (i == null)
i = new Integer(1);
i = new Integer((i.intValue()) - 1);
this.sc.setAttribute("online", i);
}
}

Servlet过滤器和监听器配置范例的更多相关文章

  1. Servlet过滤器和监听器知识总结(转)

    Servlet过滤器和监听器知识总结(转)  Servlet过滤器是 Servlet 程序的一种特殊用法,主要用来完成一些通用的操作,如编码的过滤.判断用户的登录状态.过滤器使得Servlet开发者能 ...

  2. Servlet过滤器和监听器知识总结

    Servlet过滤器是 Servlet 程序的一种特殊用法,主要用来完成一些通用的操作,如编码的过滤.判断用户的登录状态.过滤器使得Servlet开发者能够在客户端请求到达 Servlet资源之前被截 ...

  3. Servlet过滤器和监听器

    1,Servlet过滤器 <filter> <filter-name>charset</filter-name> <filter-class>org.g ...

  4. Servlet,过滤器,监听器,拦截器的区别

    1.过滤器 Servlet中的过滤器Filter是实现了javax.servlet.Filter接口的服务器端程序,主要的用途是过滤字符编码.做一些业务逻辑判断等.其工作原理是,只要你在web.xml ...

  5. Servlet过滤器,Servlet过滤器创建和配置

    第一:Servlet的过滤器的创建和配置,创建一个过滤器对象需要实现javax.servlet.Filter接口,同时实现Filter的3个方法.        第一方法是过滤器中的init()方法用 ...

  6. Servlet过滤器创建与配置

    例1 创建一个过滤器,实现网站访问计数器的功能,并在web.xml文件的配置中,将网站访问量的初始值设置为5000. (1)创建名称为CountFilter的类,该类实现javax.servlet.F ...

  7. Servlet,过滤器和监听器的配置和使用

    一.什么是Servlet Servlet使用Java语言实现的程序,运行于支持Java语言的Web服务器或者应用服务器中.Servlet先于JSP出现,提供和客户端动态交互的功能.Servlet可以处 ...

  8. ssh整合web.xml过滤器和监听器的配置 .

    延迟加载过滤器 Hibernate 允许对关联对象.属性进行延迟加载,但是必须保证延迟加载的操作限于同一个 Hibernate Session 范围之内进行.如果 Service 层返回一个启用了延迟 ...

  9. 05).30分钟学会Servlet+过滤器+监听器+实际案例

    一.Servlet简介: Servlet程序处理流程 二.Servlet程序实现 实现要求 Servlet属于java ee范畴,而java和javac属于java se范畴,要想编译servlet必 ...

随机推荐

  1. windows10下笔记本电脑外接显示器设置

    笔记本屏幕小,故外接一个显示器,方便使用. 我的电脑没有VGA接口,有HDMI接口,所以我买了一个HDMI到VGA接口转换器. 直接把外界显示器安装到笔记电脑上,如下图所示 接下来是屏幕设置 打开系统 ...

  2. Python:闭包

    闭包(Closure) 在一个函数内部定义另一个函数,然后内部函数用到外部函数的变量,把内部函数以及用到的外部变量,合称闭包. 首先复习一下 命名空间与作用域 我们可以把命名空间看做一个大型的字典类型 ...

  3. N-N

    ---情景--- 关系:角色N-N区域 基础表:角色表.区域表 关系表:主键-角色id-区域id集 ---需求--- 实现“单个区域勾选角色”且不借助与非SQL脚本(php etc)遍历 ---疑惑- ...

  4. 实例Python处理XML文件的方法

    转自:http://www.jb51.net/article/71773.htm 以下是部分代码: <?xml version="1.0" encoding="UT ...

  5. 开启 NFS 文件系统提升 Vagrant 共享目录的性能

    Vagrant 默认的 VirtualBox 共享目录方式读写性能表现并不好,好在 Vagrant 支持 NFS 文件系统方式的共享,我们可以启用 NFS 提升性能 开启方法 首先要把虚拟机的网络设置 ...

  6. Mybatis 代码自动生成[myeclipse版]

    使用环境说明: OS:windows 7 64位 myeclipse: 2017 CI 1.安装 打开myeclipse--help---Install from catalog--选择eclipse ...

  7. Unity3D中使用Profiler精确定位性能热点的优化技巧

    本文由博主(SunboyL)原创,转载请注明出处:http://www.cnblogs.com/xsln/p/BeginProfiler.html 简介 在使用Profiler定位代码的性能热点时,很 ...

  8. mysql 数据表的增删改查 目录

    mysql 表的增删改查 mysql 表的增删改查 修改表结构 mysql 复制表 mysql 删除表

  9. mysql 数据操作 多表查询 多表连接查询 外链接之左连接 右连接

    1.外链接之左连接:优先显示左表全部记录   left join 在内连接的基础上保留左表的记录 即便左表有一条记录和右表没有关系,也把他留下 mysql> select * from empl ...

  10. Core Data with Mantle

    Mantle makes it easy to write a simple model layer for your Cocoa or Cocoa Touch application.  Mantl ...