如何在struts2中配置自定义转换错误拦截器
我需要覆盖默认的转换消息 所以,我试图为我的应用程序创建一个自定义转换错误拦截器,它将被调用,而不是 struts 默认拦截器 下面提到的是代码,
public class MyConversionErrorInterceptor extends ConversionErrorInterceptor {
private static final long serialVersionUID = 1L;
protected Object getOverrideExpr(ActionInvocation invocation, Object value) {
ValueStack stack = invocation.getStack();
return (String)stack.findValue("myproj.item");
}
protected boolean shouldAddError(String propertyName, Object value) {
return true;
}}
这是提到的 struts.xml 配置。
<interceptors >
<interceptor name="conversionError" class="com.celtic.cmvs.webapp.interceptor.MyConversionErrorInterceptor" />
<interceptor-stack name="myDefaultStack">
<interceptor-ref name="conversionError" />
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
但这不起作用。 提前致谢
I need to override the default conversion messages
So, I m trying to make a custom conversion error interceptor for my application which would be called instead of struts default interceptor
Below mentioned is the code for that
public class MyConversionErrorInterceptor extends ConversionErrorInterceptor {
private static final long serialVersionUID = 1L;
protected Object getOverrideExpr(ActionInvocation invocation, Object value) {
ValueStack stack = invocation.getStack();
return (String)stack.findValue("myproj.item");
}
protected boolean shouldAddError(String propertyName, Object value) {
return true;
}}
Here is the struts.xml configuration mentioned.
<interceptors >
<interceptor name="conversionError" class="com.celtic.cmvs.webapp.interceptor.MyConversionErrorInterceptor" />
<interceptor-stack name="myDefaultStack">
<interceptor-ref name="conversionError" />
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
But it doesn't work.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我看到了一些可能性。
我的博客中有一个关于自定义拦截器的教程,可能有用: http://ddubbya.blogspot.com/2011/01/creating-custom-struts2-interceptors.html
I see a few possibilities.
I have a tutorial on custom interceptors in my blog that may be useful: http://ddubbya.blogspot.com/2011/01/creating-custom-struts2-interceptors.html