public class IsUserLoginAdvice{
public void isUserLogin() throws UserNotFoundException{
// TODO Auto-generated method stub
int id=0;
Map sessionMap=ActionContext.getContext().getSession();
System.out.println(sessionMap);
try {
//这里在一开始时userId是不存在的可能会抛出NullPointException,catch起来
id=(int) sessionMap.get("userId");
//在用户注销时我把session中的userId设为0
if(id==0){
throw new UserNotFoundException();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new UserNotFoundException();
}
}
}
<package name="struts-global" namespace="/" extends="struts-default">
<global-results>
<result name="userNotFound">/web_resource/error_jsp/user_not_found.jsp
</result>
</global-results>
<global-exception-mappings>
<exception-mapping result="userNotFound" exception="com.lsj.market.exception.UserNotFoundException"></exception-mapping>
</global-exception-mappings>
</package>
<package name="com.lsj.market.action.user" extends="struts-global">
<!-- aop设置 -->
<aop:config proxy-target-class="true">
<aop:aspect ref="isUserLoginAdvice">
<aop:pointcut id="isUserLoginPointcut"
expression="execution (* com.lsj.market.action..GetUser*.*(..))
or execution (* com.lsj.market.action..*Update*Action*.*(..))
or execution (* com.lsj.market.action..*Delete*Action*.*(..))
or execution (* com.lsj.market.action..GetMarketCar*.*(..))
or execution (* com.lsj.market.action..MarketCar*.*(..))
or execution (* com.lsj.market.action..ToFlower*.*(..))
or execution (* com.lsj.market.action..Flower*Add*.*(..))"/>
<aop:before method="isUserLogin" pointcut-ref="isUserLoginPointcut"/>
</aop:aspect>
</aop:config>
<!-- 声明advice Bean -->
<bean id="isUserLoginAdvice" class="com.lsj.market.aop.IsUserLoginAdvice"></bean>
<constant name="struts.objectFactory" value="spring" />
<!-- 总是确保使用spring的自动装备策略 --> <constant name="struts.objectFactory.spring.autoWire.alwaysRespect" value="true" />
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有