struts2学习dem002_拦截器(interceptor)和tomcat下BASIC认证
来源:互联网 发布:淘宝联盟 一淘同时使用 编辑:程序博客网 时间:2024/06/05 22:31
-----------------------------拦截器***********************************************
struts2中拦截器可以自定义,也可以使用API自带的!
他能在action被调用之前和被调用之后执行一些“代码”。
主要用于:防止重复提交、类型转换、对象封装、校验、文件上传、页面预装载等等。
每一个拦截器都是独立装载的,我们可以根据实际的需要为每一个action装配她所需要的拦截器,
例如一个action需要对象封装、文件上传,我们可以给他设置相应的两个拦截器。
1.struts2自带的拦截器存放在struts2-core-版本号.jar中的struts-default.xml 里面
例子:测试在某个action里面执行的时间。
第一种情况:如果包继承struts-default,可以直接引用struts-default.xml里面的拦截器。
<package extends="struts-default" 。。。>
<action .......>
<result></result>
<interceptor-ref name="timer"/>/*测试action执行之前和执行之后所需的时间*/
<interceptor-ref name="defaultStack"/>/*如果没写拦截器默认的包是它,如果加了拦截器,默认的拦截器就没啦。所以要手动加进去,就要像一个类的无参构造方法*/
</action>
</package>
第二种:上面的还可以这样写。拦截器嵌套拦截器
<package extends="struts-default" >
<interceptors>
<interceptor-stack name="myinter">
<interceptor-ref name="timer"/>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<action ......>
<interceptor-ref name="myinter"/>
</action>
</package>
第三种情况:就是没继承struts-default.
就要自己配置拦截器
<interceptors>
<interceptor name="timer" class="com.opensymphony.xwork2.interceptor.TimerInterceptor"></interceptor>
<interceptor name="params" class="com.opensymphony.xwork2.interceptor.ParametersInterceptor"></interceptor>
</interceptors><!-- 如果继承struts-default可以不用写拦截器,直接添加<interceptor-ref> -->
然后在<action>里面添加
<interceptor-ref name="timer"/>
<interceptor-ref name="params"/>
------------------------------------------------Tomcat容器支持下的Basic安全认证***********************************************
<!--安全验证 -->
<security-constraint>
<web-resource-collection>
<web-resource-name>
my website auth resouce
</web-resource-name>
<url-pattern>/test/*</url-pattern>/*认证的位置*/
<http-method>POST</http-method>
<http-method>GET</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<security-role>
<role-name>admin</role-name>
</security-role>
<login-config>
<auth-method>
BASIC
</auth-method>
<realm-name>
net Auth
</realm-name>
</login-config>
相关认证连接:http://www.cnblogs.com/yan5lang/archive/2010/09/25/1834364.html
- struts2学习dem002_拦截器(interceptor)和tomcat下BASIC认证
- Struts2学习笔记(九) 拦截器(Interceptor)(下)
- Struts2拦截器(Interceptor)(下)
- Struts2 - Struts2的拦截器Interceptor(从零开始学习Strust2_08)
- Struts2学习笔记(八) 拦截器(Interceptor)(上)
- struts2学习笔记之拦截器(Interceptor)
- Struts2拦截器Interceptor学习笔记
- struts2 学习总结 ---- 拦截器(interceptor)
- 【转载】struts2 学习总结 ---- 拦截器(interceptor)
- struts2学习笔记之拦截器(Interceptor)
- Struts2 拦截器(Interceptor )原理和配置
- Struts2 拦截器(Interceptor )原理和配置
- Struts2 拦截器(Interceptor )原理和配置
- Struts2 拦截器(Interceptor )原理和配置
- Struts2 拦截器(Interceptor )原理和配置
- Struts2 拦截器(Interceptor )原理和配置
- Struts2拦截器(Interceptor)
- Struts2拦截器(Interceptor)
- SQL注入式攻击
- 一切尽在掌握 -- kconfig
- Gram-Schmidt正交化及其修正方法的matlab实现
- c++中string类字符串和c中char*/char[]型型字符串的区别
- C++通过函数实现复数相加
- struts2学习dem002_拦截器(interceptor)和tomcat下BASIC认证
- 第2章练习题
- 关于嵌入式Linux系统flash分区设计及文件系统格式选择的一些浅见
- VS2008 MFC开发总结
- c语方学习笔记六
- java中json操作xml和生成xml
- android---LinearLayout,listener的计算器小实例
- Debug与Release版本区别
- JavaWeb 之 HttpServletRequest