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过滤器和监听器配置范例

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

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

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

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

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

  5. 动手学servlet(六) 过滤器和监听器

     过滤器(Filter) 过滤器是在客户端和请求资源之间,起一个过滤的作用,举个例子,比如我们要请求admin文件夹下的index.jsp这个页面,那么我们可以用一个过滤器,判断登录用户是不是管理员 ...

  6. 面试之servlet、过滤器、监听器

    servlet.过滤器.监听器servlet是Java中WEB请求和响应的容器servlet的运行需要在类似tomcat容器中,一个 Web 应用对应一个 Context 容器,也就是 Servlet ...

  7. TODO java-web相关 servlet过滤器+监听器

    servlet过滤器 定义: 过滤器是小型的web组件,它负责拦截请求和响应,以便查看.提供或以某种方式操作正在客户机和服务器之间交换的数据. 与过滤器相关的servlet共包含3个简单接口:Filt ...

  8. Servlet过滤器Filter和监听器

    一.Servlet过滤器的概念: *********************************************************************************** ...

  9. 6.Servlet、Filter过滤器以及监听器

    Servlet 是运行在Web服务器端的Java程序,它使用Java语言编写,与Java程序的区别是Servlet对象主要封装了对HTTP请求的处理,并且它的运行需要Servlet容器的支持,在Jav ...

随机推荐

  1. 宿主机( win 7 系统) ping 虚拟机VMware( cent os 6.6 ) 出现“请求超时”或者“无法访问目标主机”的解决方法

    首先虚拟机的网络连接设置为"Host-only": 然后在 cmd 窗口中查看 VMnet1 的 ip 地址,这里是 192.168.254.1 接下来在 Linux 中设置网卡地 ...

  2. SpringMVC 配置log4j

    log4j.properties相关 http://www.cnblogs.com/ITEagle/archive/2010/04/23/1718365.html http://www.cnblogs ...

  3. UVa 1347 Tour

    Tour Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Description   Joh ...

  4. UVa 1025 A Spy in the Metro

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35913 预处理出每个时间.每个车站是否有火车 为了方便判断是否可行,倒推处理 ...

  5. 点击cell弹出一个日期选择器

    - (void)setUpGroup2 { ILGroupItem *group = [[ILGroupItem alloc] init]; // 结束时间 ILSettingItem *endTim ...

  6. spring mvc静态资源文件的引用

    在页面的<title>下 <link rel="stylesheet" href="<%=request.getContextPath()%> ...

  7. HTTP协议详解(一直在用可是这篇太好了转一下)

    引言 HTTP是一个属于应用层的面向对象的协议,由于其简捷.快速的方式,适用于分布式超媒体信息系统.它于1990年提出,经过几年的使用与发展,得到不断地完善和扩展.目前在WWW中使用的是HTTP/1. ...

  8. javascript仿天猫加入购物车动画效果

    javascript仿天猫加入购物车动画效果   注意:首先需要声明的是:代码原思路不是我写的,是在网上找的这种效果,自己使用代码封装了下而已:代码中都有注释,我们最主要的是理解抛物线的思路及在工作中 ...

  9. Windows环境下 Node和NPM个性安装

    常拿自己的电脑常用来测试各种Bug,所以始终奋斗在XP.IE6的环境下.让我们在如此级别的环境下,开始Node之路吧~~ 在过去,Node.js一直不支持在Windows平台下原生编译,需要借助Cyg ...

  10. iOS多线程GCD(转)

    转自:http://www.cnblogs.com/pure/archive/2013/03/31/2977420.html Grand Central Dispatch (GCD)是Apple开发的 ...