我有一个自定义标签,我想在页面调用该标签时,spring能拦截标签的doStartTag方法,做一些相关操作,以下是自定义标签代码
/**
*
*/
package com.hinge.bi.taglib;
/**
* @author
*/
import java.util.List;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;
import com.hinge.bi.service.explorer.ResourceServiceI;
import com.hinge.bi.service.taglib.TagLibServiceI;
import com.hinge.bi.service.useradmin.UserServiceI;
public class UserExploreList extends TagSupport
{
public UserExploreList()
{
super();
}
public int doStartTag() throws JspTagException
{
System.out.println( "Hello Sunning ");
return EVAL_BODY_INCLUDE;
}
public int doEndTag() throws JspTagException
{
return EVAL_PAGE;
}
}
以下是spring 的环绕通知代码
-----------------------------------------------
package com.hinge.bi.taglib.aop;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import com.hinge.bi.service.explorer.ResourceServiceI;
import com.hinge.bi.service.useradmin.UserServiceI;
public class PurviewInspect implements MethodInterceptor
{
private UserServiceI userService;
private ResourceServiceI resourceService;
public void setResourceService(ResourceServiceI resourceService)
{
this.resourceService = resourceService;
}
public void setUserService(UserServiceI userService)
{
this.userService = userService;
}
public Object invoke(MethodInvocation invocation) throws Throwable
{
System.out.println( "Hello Sunnning ");
HttpServletRequest request = (HttpServletRequest) invocation.getArguments()[2];
HttpServletResponse response=(HttpServletResponse) invocation.getArguments()[3];
String method=request.getParameter( "action ");
if (true)
{
response.sendRedirect( "/hingebi/control/login.jsp ");
return null;
}
Object result = invocation.proceed(); // 调用MyBuyBook中的buyBook方法,即真实操作
return result;
}
}
以下是spring中的配置
<?xml version= "1.0 "?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN " "http://www.springframework.org/dtd/spring-beans.dtd ">
<beans>
<bean id= "userExploreList " class= "com.hinge.bi.taglib.UserExploreList ">
</bean>
<!-- advice配置-->
<bean id= "explorePurviewInspect " class= "com.hinge.bi.taglib.aop.PurviewInspect ">
<property name= "userService ">
<ref bean= "userService " />
</property>
<property name= "resourceService ">
<ref bean= "resourceService " />
</property>
</bean>
<bean id= "explorePurviewInspectAdvisor " class= "org.springframework.aop.support.NameMatchMethodPointcutAdvisor ">
<property name= "mappedName " value= "doStartTag ">
</property>
<property name= "advice " ref= "explorePurviewInspect ">
</property>
</bean>
<!-- 装配advisor-->
<bean id= "theAdvisor " class= "org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator ">
<property name= "beanNames ">
<value> userExploreList </value>
</property>
<property name= "interceptorNames ">
<list>
<value> explorePurviewInspectAdvisor </value>
</list>
</property>
</bean>
</beans>
但是在运行含有该标签的jsp时,总是直接就运行doStartTag方法了,spring没有起到拦截的作用。。
分享到:
相关推荐
spring aop切面拦截指定类和方法实现流程日志跟踪 一般情况下,在不侵入业务代码的情况下,需要做流程日志跟踪是比较合理的 采用springaop切面思想
项目中含有一整个springboot实现aop的功能,在拦截的方法形式上有两种一种是通过切点设置为拦截某个包路径下面的类中的所有方法;还有一种是基于某个自定义注解的.
NULL 博文链接:https://chaoyi.iteye.com/blog/2166029
spring-boot 拦截器 登录拦截spring-boot 拦截器 登录拦截spring-boot 拦截器 登录拦截spring-boot 拦截器 登录拦截
Spring AOP四种创建通知(拦截器)类型
Spring框架是一个开放源代码的J2EE应用程序框架,由Rod Johnson发起,是...Spring框架主要由七部分组成,分别是 Spring Core、 Spring AOP、 Spring ORM、 Spring DAO、Spring Context、 Spring Web和 Spring Web MVC。
Spring Mvc AOP通过注解方式拦截controller等实现日志管理
spring boot jpa连接数据库,设置拦截器拦截指定路径下的文件。
NULL 博文链接:https://free9277.iteye.com/blog/1935492
springMybatis,springmvc,环绕通知,时间转换,des,md5加密账户密码.拦截器
NULL 博文链接:https://conkeyn.iteye.com/blog/2354644
用spring写的小示例程序,拦截某一层的所有方法。可以在调用之前、之后、抛出异常拦截调用,日志打印。
Spring AOP 拦截器 Advisor Spring AOP 拦截器 Advisor
1、编写切面类,包含权限审核方法和日志记录方法,这两个方法将来会织入到...5、编写案例,运用Spring AOP技术,要求包含前置通知、后置通知、环绕通知、返回通知、异常返回通知。请掌握这五种通知的特点,及应用场景
springaop拦截controller日志
spring aop 拦截 实例spring aop 拦截 实例spring aop 拦截 实例
spring拦截器,高级参数绑定,controller返回值
这一版本的项目中新增了拦截器的一个demo
针对spring boot 集成jpa sql操作进行自定义分库分表逻辑
NULL 博文链接:https://baobeituping.iteye.com/blog/1208293