Struts2:拦截器和参数
我用 Struts 2 做了一些页面。(J2EE 项目) 一切都很好,直到我尝试添加拦截器。
拦截器似乎删除了 jsp 发送的类操作和参数的所有属性,其 url 如下: action?param=xxx
这里是拦截器:
public class SessionInterceptor extends AbstractInterceptor{
@Override
public String intercept(ActionInvocation invocation) throws Exception {
return invocation.invoke();
}
这里是 struts .xml:
<action name="movefc_ShowFjt" class="struts2.ShowFjtAction" method="movefc">
<interceptor-ref name="sessionInterceptor"></interceptor-ref>
<result name="input" type="dispatcher">jsp/showFjt.jsp</result>
<result name="success" type="dispatcher">jsp/showFjt.jsp</result>
</action>
在类操作中,
public class ShowFjtAction extends ActionSupport {
private String param;
private Personne p;
param 属性永远不会从 jsp 接收值(拦截器关闭时也可以)。更糟糕的是,集体诉讼中的其他属性似乎被删除了。 这是拦截器的return invocation.invoke();的正常效果吗? 我能做些什么来解决这个问题吗?
i have done some pages with Struts 2.(J2EE project)
All was ok until i try to add an interceptor.
It seems that the Interceptor delete all properties of my Class Action and Parameters send by the jsp with url like: action?param=xxx
here is the interceptor:
public class SessionInterceptor extends AbstractInterceptor{
@Override
public String intercept(ActionInvocation invocation) throws Exception {
return invocation.invoke();
}
here is the struts.xml:
<action name="movefc_ShowFjt" class="struts2.ShowFjtAction" method="movefc">
<interceptor-ref name="sessionInterceptor"></interceptor-ref>
<result name="input" type="dispatcher">jsp/showFjt.jsp</result>
<result name="success" type="dispatcher">jsp/showFjt.jsp</result>
</action>
in the class action,
public class ShowFjtAction extends ActionSupport {
private String param;
private Personne p;
param property never receive value from the jsp (it is ok when interceptor is off). Worse, other properties in Class action seems to be erased.
Is that an normal effect of the return invocation.invoke(); of the interceptor ?
Is there anything i can do to fix that ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
定义自己的拦截器是否会导致所有默认拦截器被丢弃?
您是否应该定义一个包含拦截器和默认堆栈的拦截器堆栈?
y defining your own interceptor are you causing all of the default interceptors to be discarded?
Should you perhaps be defining an interceptor stack which includes your interceptor and the default stack?
整个概念解释如下
1] 首先,当用户没有编写任何拦截器时,将使用struts-default.xml中定义的拦截器。它是在struts-core.jar中定义的,它是通过扩展我们的包xml标签中扩展的“struts-default”来完成的。
2]当用户编写自己的拦截器时,如果您在 sessionInterceptor ref name 之后添加一个模式代码块,即 interceptor-ref name="defaultStack" 将解决您的问题。
在尝试此操作之前,请尝试解压缩 struts-core.jar 并继续实施。
The entire concept is explained as follows
1] First when user does not writes any interceptors, then interceptors defined in struts-default.xml will be used. It is defined in struts-core.jar, it is accomplished by extending the "struts-default" extended in our package xml tag.
2] When user writes his own interceptor if you add one mode code block after sessionInterceptor ref name i.e interceptor-ref name="defaultStack" will solve your problem.
Befor trying this try to unzip the struts-core.jar and move forward with your implementation.