进入jsp页面后访问没有进过拦截器拦截 直接进去action的处理类 配置看了好久 找不出来哪里错了 求各位大神指点迷津。。。。
自定义拦截器: 登录即可查询 没登录查询不了 登录后不是admin 无法进行商品操作
@Override
public String intercept(ActionInvocation actionInvocation) throws Exception {
// 得到被拦截的actionContext所有对象
ActionContext actionContext = actionInvocation.getInvocationContext();
// 从session中获得role角色对象
String role = (String) actionContext.getSession().get("role");
System.out.println(role);
// 得到request对象
Map request = (Map) actionContext.get("request");
if (role == null) {
request.put("msg", "没有登录,请<a href = 'index.jsp'>重新登录</a>");
return "error";
} else {
String method = actionInvocation.getProxy().getMethod()
.toLowerCase();
if (!role.equals("admin")
&& (method.contains("add") || method.contains("del") || method
.contains("update"))) {
request.put("msg", "不是管理员,没有权限进行这项操作 <a href = 'javascript:history.go(-1)'>返回</a>");
return "error";
}
}
return actionInvocation.invoke();
}
jsp页面 没有进过拦截 直接调用了action处理类的对应方法
<body>
<h2>订单管理系统操作功能列表
<hr/>
<ul><a href= "cust!queryCust.action">查询客户</a></ul>
<ul><a href= "cust!addCust.action">添加客户</a></ul>
<ul><a href= "shop!addShop.action">添加商品</a></ul>
<ul><a href= "shop!updateShop.action">修改商品</a></ul>
</h2>
Struts.xml
<package name="intercepter" extends="struts-default">
<interceptors>
<interceptor name="auth" class="com.intercepter.MyIntercepter"></interceptor>
</interceptors>
<default-interceptor-ref name="auth"/>
<global-results><result name = "error">/error.jsp</result></global-results>
<action name = "cust" class = "com.action.CustAction">
</action>
<action name = "shop" class = "com.action.ShopAction">
</action>
</package>