Struts2:拦截器被调用,但不是 Action 类
这是我的 struts.xml 文件。正如您所看到的,配置了一个操作类和一个拦截器。
我的问题是,正在调用拦截器,而不是操作类。
(在教程中,我读到拦截器执行后它会调用操作类方法)
请参阅我的代码:
<struts>
<package name="test" extends="struts-default">
<interceptors>
<interceptor name="loginkiran" class="vaannila.MyLoginInterCeptor" />
</interceptors>
<action name="HelloWorld" class="vaannila.HelloWorld" method="kiran">
<interceptor-ref name="loginkiran" />
<result name="SUCCESS">/success.jsp</result>
</action>
</package>
</struts>
这是我的操作类的 kiran 方法
public class HelloWorld {
public String kiran() {
System.out.println("Hi inside the Kiran Method");
return "SUCCESS";
}
}
=========== =============
这是我的拦截器类
public class MyLoginInterCeptor implements Interceptor {
@Override
public String intercept(ActionInvocation invocation) throws Exception {
System.out.println("The server Port is"+str);
return invocation.invoke();
}
}
This is my struts.xml file. As you can see an action class and an interceptor are configured.
My question is that, the interceptor is being called, but not the action class.
(Where as in tutorials, I read that after interceptor is executed it calls the action class method)
Please see my code:
<struts>
<package name="test" extends="struts-default">
<interceptors>
<interceptor name="loginkiran" class="vaannila.MyLoginInterCeptor" />
</interceptors>
<action name="HelloWorld" class="vaannila.HelloWorld" method="kiran">
<interceptor-ref name="loginkiran" />
<result name="SUCCESS">/success.jsp</result>
</action>
</package>
</struts>
This is my Action class's kiran method
public class HelloWorld {
public String kiran() {
System.out.println("Hi inside the Kiran Method");
return "SUCCESS";
}
}
========================
This is my Interceptor class
public class MyLoginInterCeptor implements Interceptor {
@Override
public String intercept(ActionInvocation invocation) throws Exception {
System.out.println("The server Port is"+str);
return invocation.invoke();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您尚未定义 INPUT 结果。在 struts.xml 中定义它并直接进入带有标签的页面
,您就会找出问题所在。如果这不起作用,请尝试这个
You haven't defined the INPUT result. Define it within struts.xml and direct to a page with
tag and you'll figure out what was going wrong. If that doesn't work, try this
你错过了defaultStack。
在您提到的拦截器引用下方添加
You missed the defaultStack.
Add
<interceptor-ref name="defaultStack"></interceptor-ref>
, below your mentioned interceptor reference请编写
System.out.println(inspiration.invoke());
并检查它返回的内容。将 try/catch 块添加到您的代码中,它会给您一个想法。我认为invoke()
方法失败了。Please write
System.out.println(invocation.invoke());
and check what it returns. Add try/ catch block to your code it will give you an idea. I think it is failing ininvoke()
method.