【新手】struts2拦截器不生效问题求助
AuthInterceptor
package dzxczx.blog.admin;
import com.opensymphony.xwork2.interceptor.Interceptor;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionContext;
import java.util.Map;
public class AuthInterceptor implements Interceptor{
public void init() {
System.out.println("初始化");
}
public String intercept(ActionInvocation invocation) throws Exception{
ActionContext ctx = ActionContext.getContext();
Map<String, Object> session = ctx.getSession();
System.out.print(1);
if ((String)session.get("admin") != null) {
return invocation.invoke();
} else {
return "error";
}
}
public void destroy() {
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0" metadata-complete="true">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
</web-app>
struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.action.extension" value="action" />
<package name="index" extends="struts-default">
<action name="index" class="dzxczx.blog.IndexAction">
<result name="success">/WEB-INF/content/index.jsp</result>
</action>
</package>
<package name="admin" namespace="admin" extends="struts-default">
<interceptors>
<interceptor name="dzxczxauth" class="dzxczx.blog.admin.AuthInterceptor"></interceptor>
<interceptor-stack name="dzxczxStack">
<interceptor-ref name="dzxczxauth"/>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<action name="index" class="dzxczx.blog.admin.IndexAction">
<result name="success">/WEB-INF/content/admin/index.jsp</result>
<result name="error">/WEB-INF/content/error.jsp</result>
<interceptor-ref name="dzxczxStack" />
</action>
<action name="login" class="dzxczx.blog.admin.LoginAction">
<result name="success">/WEB-INF/content/admin/login.jsp</result>
</action>
</package>
</struts>
访问admin/index.action 控制台能输出自定义拦截器里的init方法的内容 但是 intercept方法不会输出东西 研究了好一会没研究明白 求助各位大神
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对Struts 不熟悉
谢邀,但我对
struts
不太熟悉