后台权限拦截器编写

网友投稿 522 2022-11-13

后台权限-编写

后台权限-编写

package cn.itcast.shop.Interceptor;import org.apache.struts2.ServletActionContext;import cn.itcast.shop.vo.AdminUser;import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.ActionSupport;import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;/** * 后台用户登录权限-(Action文件拦截,在action中配置拦截) * * @author 吕小刚 * @version V1.0 * */// 继承AbstractInterceptor子类MethodFilterInterceptor-@SuppressWarnings("serial")public class PrivilegeInterceptor extends MethodFilterInterceptor { @Override // 执行拦截的方法 protected String doIntercept(ActionInvocation actionInvocation) throws Exception { // 判断Session中是否保存了后台用户信息 AdminUser adminUser = (AdminUser) ServletActionContext.getRequest().getSession().getAttribute("adminUser"); if (adminUser == null) { // 没有登录进行访问 // 对继承过ActionSupport类里面的方法进行拦截 ActionSupport actionSupport = (ActionSupport) actionInvocation.getAction(); actionSupport.addFieldError("loginFail", "亲!你还没有登录!没有访问权限!"); return "loginFail"; } else { // 已经登录过 return actionInvocation.invoke(); } }}

/WEB-INF/jsp/msg.jsp /WEB-INF/jsp/login.jsp /admin/index.jsp /WEB-INF/jsp/index.jsp /WEB-INF/jsp/regist.jsp /WEB-INF/jsp/{1}.jsp /WEB-INF/jsp/login.jsp index index /WEB-INF/jsp/product.jsp /WEB-INF/jsp/productList.jsp /WEB-INF/jsp/productList.jsp /WEB-INF/jsp/cart.jsp cart_addCart cart_addCart cart_addCart /WEB-INF/jsp/order.jsp /WEB-INF/jsp/orderList.jsp /WEB-INF/jsp/order.jsp /admin/index.jsp /admin/home.jsp /admin/category/list.jsp /admin/category/add.jsp adminCategory_findAll.action adminCategory_findAll.action /admin/category/edit.jsp adminCategory_findAll.action /admin/categorySecond/list.jsp /admin/categorySecond/add.jsp adminCategorySecond_findAll.action?page=1 adminCategorySecond_findAll.action?page=1 /admin/categorySecond/edit.jsp adminCategorySecond_findAll.action?page=1 /admin/product/list.jsp /admin/product/add.jsp adminProduct_findAll.action?page=1 adminProduct_findAll.action?page=1 /admin/product/edit.jsp adminProduct_findAll.action?page=1 /admin/order/list.jsp /admin/order/orderItem.jsp adminOrder_findAll.action?page=1

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:HashSet如何保证元素不重复(面试必问)
下一篇:集合框架_Map集合的遍历之键值对对象找键和值
相关文章

 发表评论

暂时没有评论,来抢沙发吧~