`
wyzuomumu
  • 浏览: 104948 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

web.xml 配置Filter

    博客分类:
  • WEB
阅读更多

下面是该Filter的源代码。

程序清单:codes/02/2.12/ filterTest/WEB-INF/src/lee/AuthorityFilter.java

 



上面Filter的doFilter方法里3行斜体字代码用于获取Filter的配置参数,而程序中粗体字代码则是此Filter的核心,①号代码按配置参数设置了request编码所用的字符集,接下来的粗体字代码判断session范围内是否有user属性——没有该属性即认为没有登录,如果既没有登录,而且请求地址也不是登录页和处理登录页,系统直接跳转到登录页面。

在web.xml文件中配置该Filter,使用init-param元素为该Filter配置参数,init-param可接受如下两个子元素:

param-name:指定参数名。

param-value:指定参数值。

该Filter的配置片段如下:

 


上面配置片段中粗体字代码为该Filter指定了3个配置参数,指定loginPage为/login.jsp,proLogin为/proLogin.jsp,这表明:如果没有登录该应用,普通用户只能访问/login.jsp和/proLogin.jsp页面。只有当用户登录该应用后才可自由访问其他页面。

 

 

<servlet>
    <servlet-name>action<servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
        <param-name>config</param-name>
        <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>

    <init-param>
        <param-name>detail</param-name>
        <param-value>2</param-value>
    </init-param>

    <init-param>
        <param-name>debug</param-name>
        <param-value>2</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>




<load-on-startup>2</load-on-startup>配置的作用
1)load-on-startup元素标记容器是否在启动的时候就加载这个servlet(实例化并调用其init()方法)。
2)它的值必须是一个整数,表示servlet应该被载入的顺序
3)当值为0或者大于0时,表示容器在应用启动时就加载并初始化这个servlet;
4)当值小于0或者没有指定时,则表示容器在该servlet被选择时才会去加载。
5)正数的值越小,该servlet的优先级越高,应用启动时就越先加载。
6)当值相同时,容器就会自己选择顺序来加载。

本文来自CSDN博客,转载出处:http://blog.csdn.net/doymm2008/archive/2009/11/09/4791435.aspx

分享到:
评论

相关推荐

    Filter过滤器的代码及其web.xml配置代码

    Filter过滤器的代码及其web.xml配置代码 很好的解决网页乱码问题,很方便,只要按照名字添加就可以了

    web.xml 配置详解

    web.xml 配置详解,需要的下载了。。。Web.xml常用元素和在java web规范中说明.按照listner,filter,servlet的顺序初始化

    web.xml配置servlet,filter,listener加载顺序源代码

    本源码将详细介绍web.xml配置中servlet,filter,listener的加载顺序,可以让学习者更好的了解web.xml各种属性配置,自己写的东西,不足之处请大家见谅,顺便收点积分也好下资料,谢谢

    关于web.xml配置文件servlet,filter,listener加载顺序

    关于filter、servlet在web.xml配置及加载顺序

    web.xml详细说明

    用于 web.xml 配置详解。例如: &lt;web-app&gt; &lt;display-name&gt;&lt;/display-name&gt;定义了WEB应用的名字 &lt;description&gt;&lt;/description&gt; 声明WEB应用的描述信息 &lt;context-param&gt;&lt;/context-param&gt; context-param元素声明应用...

    flex4,struts2.3兼容配置web.xml中的filter

    flex4,struts2.3兼容配置web.xml中的filter

    Web后端开发-使用Filter过滤器技术,实现访问量统计-方法二使用web.xml配置的方式

    Web后端开发-使用Filter过滤器技术,实现访问量统计-方法二使用web.xml配置的方式

    web.xml文件中配置(servlet, spring, filter, listenr)的加载顺序

    java servlet spring web filter listenr

    jsp web.xml文件的作用及基本配置

    web.xml文件是用来配置:欢迎页、servlet、filter等的。当你的web工程没用到这些时,你可以不用web.xml文件来配置你的web工程。 那么web.xml能做的所有事情都有那些? 其实,web.xml的模式(Schema)文件中定义了多少...

    Web.xml的作用及常用标签的功能

    web.xml文件是用来初始化工程配置信息的,比如说welcome页面,filter,listener,servlet,servlet-mapping,启动加载级别等等,当你的web工程中没用到这些当然也就不需要这个xml文件来配置你的apllication了 ...

    ehcahe页面缓存详细内容

    3.在工程中web.xml配置过滤器 &lt;filter&gt; &lt;filter-name&gt;SimplePageCachingFilter&lt;/filter-name&gt; &lt;filter-class&gt;net.sf.ehcache.constructs.web.filter.SimplePageCachingFilter &lt;/filter-class&gt; &lt;/filter&gt; ...

    tomcat解决跨域访问问题配置

    1、修改tomcat下的Conf/web.xml文件,在该文件内容中新增以下配置,注意,若该web.xml中存在其它filter,则需要将该filter放在所有filter前面; &lt;filter&gt; &lt;filter-name&gt;CorsFilter&lt;/filter-name&gt; &lt;filter-class&gt;...

    filter配置解决乱码问题

    web.xml配置filter和filtermapping,编写类 读取或写死filter的init-params中的字符编码传入 reqeust中 调用dofilter方法,乱码解决

    Web配置详解

    jsp的web.xml配置说明 Web.xml常用元素&lt;web-app&gt;&lt;display-name&gt;&lt;/display-name&gt;定义了WEB应用的名字&lt;description&gt;&lt;/description&gt; 声明WEB应用的描述信息&lt;context-param&gt;&lt;/context-param&gt; context-param元素声明应用...

    JAVA WEB 开发详解:XML+XSLT+SERVLET+JSP 深入剖析与实例应用.part3

    本书共分4部分,从xml、servlet、jsp和应用的角度向读者展示了java web开发中各种技术的应用,循序渐进地引导读者快速掌握java web开发。.  本书内容全面,涵盖了从事java web开发所应掌握的所有知识。在知识的讲解...

    web配置文件.txt

    而POST请求中,如果出现中文时,会导致程序无法正常运行,会出现中文乱码问题,所以就必须在web.xml中配置POST请求中文乱码问题 &lt;filter&gt; &lt;filter-name&gt;encodingFilter&lt;/filter-name&gt; &lt;filter-class&gt;org.spring...

    shiroFilter权限验证

    -- authc:该过滤器下的页面必须验证后才能访问,它是Shiro内置的一个拦截器org.apache.shiro.web.filter.authc.FormAuthenticationFilter --&gt; &lt;property name="filterChainDefinitions"&gt; /statics/**=anon ...

    如何配置Filter过滤器处理JSP中文乱码

    配置Filter过滤器处理JSP中文乱码 参考Tomcat服务器目录webapps的examples示例 简单配置步骤: 1.在项目web.xml文件添加过滤器标记&lt;filter&gt;和&lt;filter-mapping&gt;; 2.实现过滤器代码; 3.对Tomcat服务器conf目录里的...

    filter对request请求拦截,对请求参数进行修改

    除了添加两个JsFilter.java和GetHttpServletRequestWrapper.java之外,需要在web.xml添加对应的配置。 &lt;!-- 特殊字符过滤 --&gt; &lt;filter&gt; &lt;filter-name&gt;sqlFilter&lt;/filter-name&gt; &lt;filter-class&gt;weixin.idea.waiting...

    struts-2.5.13

    2.配置web.xml &lt;filter&gt; &lt;filter-name&gt;struts2&lt;/filter-name&gt; &lt;!-- 过滤器的名字 --&gt; &lt;filter-class&gt;org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter&lt;/filter-class&gt; &lt;!-- 引用个...

Global site tag (gtag.js) - Google Analytics