struts2实现拦截器的方法
2019独角兽企业重金招聘Python工程师标准>>>
jsp页面
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<s:debug></s:debug>
${message}
<form action="login.action" method="post">
用户名:<input type="text" name="username"><br>
密码:<input type="text" name="passoword"><br>
<input type="submit" value="提交">
</form>
</body>
</html>
Action方法
package com.action;
import com.opensymphony.xwork2.ActionSupport;
public class InterAction extends ActionSupport {
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println("123");
return super.execute();
}
}
下面写自己的interceptor
package com.interceptor;
import model.User;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
public class FirstInterceptor implements Interceptor {
@Override
public void destroy() {
// TODO Auto-generated method stub
System.out.println("FirstInterceptor is destroyed...");
}
@Override
public void init() {
// TODO Auto-generated method stub
System.out.println("FirstInterceptor is inited ....");
}
@Override
public String intercept(ActionInvocation arg0) throws Exception {
// TODO Auto-generated method stub
Object u=ActionContext.getContext().getSession().get("user");
if(u==null)
{
ActionContext.getContext().getSession().put("message","重新登录");<!--把参数返回给jsp页面-->
return "fail";
}
return arg0.invoke();
}
}
struts.xml
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<package name="default" namespace="/" extends="struts-default">
<interceptors>
<interceptor name="firstInterceptor" class="com.interceptor.FirstInterceptor">
</interceptor>
<!-- 加到自己设置的拦截器栈里边去 -->
<interceptor-stack name="myStack">
<interceptor-ref name="firstInterceptor">
</interceptor-ref>
<interceptor-ref name="defaultStack">
</interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="myStack">
</default-interceptor-ref>
<action name="login" class="com.action.InterAction">
<result name="success">/successLogin.jsp</result>
<result name="fail">/index.jsp</result>
</action>
</package>
</struts>
转载于:https://my.oschina.net/u/1254855/blog/171189
struts2实现拦截器的方法相关推荐
- struts2自定义拦截器并配置拦截器使其生效
首先编写一个struts2的拦截器,要继承 MethodFilterInterceptor 并获取其中的方法 package star.july.d_interceptor;import com.op ...
- (转)Struts2的拦截器
http://blog.csdn.net/yerenyuan_pku/article/details/68648101 Struts2的拦截器 拦截器的概述 拦截器,在AOP(Aspect-Orien ...
- Struts2之拦截器篇
拦截器是Struts2框架的核心和基础,Struts2绝大多数功能都是通过拦截器来完成的,当StrutsPrepareAndExecuteFilter拦截到用户请求后,大量拦截器会对该请求进行处理,然 ...
- Struts2 自定义拦截器
所属栏目:AbstractInterceptor 如果要编写自定义拦截器,那么可以只用实现com.opensymphony.xwork2.interceptor.Interceptor这个接口即可. ...
- Struts2【拦截器】就是这么简单
2019独角兽企业重金招聘Python工程师标准>>> 什么是拦截器 拦截器Interceptor.....拦截器是Struts的概念,它与过滤器是类似的...可以近似于看作是过滤器 ...
- java中拦截这个类的方法_类拦截器和方法拦截器
一.拦截器 1.拦截器小介 拦截器的功能类似于web.xml文件中的Filter,能对用户的请求进行拦截,通过拦截用户的请求来实现对页面的控制.拦截器是在Struts-core-2.2.3.jar中进 ...
- Struts2配置拦截器
配置拦截器有三个步骤: 第一:先创建一个拦截器的包 com.bdqn.interceptor package com.bdqn.interceptor;import com.opensymphony. ...
- 拦截器HandlerInterceptor+方法参数解析器HandlerMethodArgumentResolver用于统一获取当前登录用户信息
文章目录 前言 一.拦截器+方法参数解析器 是什么? 二.具体实现步骤 1.自定义权限拦截器LoginInterceptor拦截所有request请求,并将token解析为currentUser,最终 ...
- Struts2 自定义拦截器(方法拦截器)
转自:http://05061107cm.iteye.com/blog/365504 struts2系统自带了很多拦截器,有时需要我们自己定义,一般有两种方式: 一.实现Interceptor接口 J ...
最新文章
- linux0.11内核编译,编译Linux-0.11内核
- [codevs 1343] 蚱蜢(省队选拔赛湖南)
- Linux 自动删除N天前的文件
- Commonjs规范及Node模块实现
- Flink JDBC Connector:Flink 与数据库集成最佳实践
- 补习系列(5)-springboot- restful应用
- Arthas 实战,助你解决同名类依赖冲突问题
- Linked List Cycle给定一个链表,判断其中是否有环。
- php项目推荐,php教程推荐:最值得推荐的10个php教程
- linux pthread头文件,pthread t 头文件_uint8 t 头文件_pthread t 头文件
- 高含盐废水处理资源化——双极膜电渗析
- django里template中的书名号
- Python手写强化学习Q-learning算法玩井字棋
- JZOJ5912 Van♂Usee
- java socket ascii_TCP套接字上的ASCII - java
- PHP脚本中的两种换行符的区别
- css3图片倾斜3D效果
- PHP获取客户端和服务器端IP
- 【AtCoder】【思维】【图论】Splatter Painting(AGC012)
- 四、Scala从入门到精通一一循环控制
热门文章
- 认清企业现状,做好信息化建设
- java学习笔记(四)----对象、数组作为参数传递,静态变量、静态方法的使用,内部类,使用文档注释
- 【Linux 内核 内存管理】Linux 内核内存布局 ④ ( ARM64 架构体系内存分布 | 内核启动源码 start_kernel | 内存初始化 mm_init | mem_init )
- 【错误记录】Flutter 混合开发报错 ( Android 端与 Flutter 端 EventChannel 初始化顺序错误导致无法通信 | EventChannel 通信流程 )
- 【Android 异步操作】Handler ( 主线程中的 Handler 与 Looper | Handler 原理简介 )
- 【Netty】NIO 缓冲区 ( Buffer ) 分散 Scattering 与 聚合 Gathering 操作
- 【C++ 语言】异常 ( 抛出字符串异常 | 抛出异常对象 | 抛出任意对象 | 抛出自定义异常 )
- Vue状态管理之Vuex
- Charles抓包https
- 【BZOJ4764】弹飞大爷 LCT