struts 2动作没有setter getter [英] struts 2 action with no setter getter

查看:113
本文介绍了struts 2动作没有setter getter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为来自用户界面的数据创建一个没有setter和getter属性的动作类。相反,我想在我自己的构建器类中使用 ServletActionContext.getRequest()。getParameterMap()来构造对象。

I would like to create an action class with no setter and getter on properties for the data coming from the user interface. Instead, I would like to use ServletActionContext.getRequest().getParameterMap() in my own builder class to construct the object.

我创建了没有属性的 Action 类。当我提交表单时,我遇到了 ognl.OgnlException:对于setProperty,target为null(null,field-name,[Ljava.lang.String; @ 5513fab7)

I had created my Action class with no properties. When I am submitting my form I am running into ognl.OgnlException: target is null for setProperty(null, "field-name", [Ljava.lang.String;@5513fab7)

是否需要任何其他约定或配置来传达Struts2框架以不设置属性并停止避免上面收到的异常?

Is there any additional conventions or configurations required to convey Struts2 framework to not set properties and stop avoid the exception I am receiving above?

推荐答案

您可以从 params 拦截器通过将参数 excludeParams 设置为拦截器。默认情况下,此参数初始化为

You can exclude some properties from the accepted parameters for params interceptor by setting parameter excludeParams to the interceptor. By default this parameter is initialized with

<interceptor-ref name="params">
  <param name="excludeParams">dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,parameters\...*</param>
</interceptor-ref>

您应该在这里添加属性,它接受正则表达式模式以匹配属性名称。可以通过 ParameterNameAware 实施的操作可以删除上面给出的限制。

You should add you properties here, it accepts the regex pattern to match the property names. The strategy applied with accepted parameter names could be compromised via the ParameterNameAware implemented actions where you could remove the restriction given above.

要更具体地说明来自用户界面的数据,我会将参数附加到 interceptor-ref 元素在启动时应用于拦截器,不存储在配置管理器的其他位置。这意味着您无法在运行时获取此参数,只能通过更新和重新加载配置文件 struts.xml 来更改。如果您将配置保存在安全的地方并且不受修改,那么您可以对正在运行的应用程序安全性提出更多声明。

To be more specific about "data coming from the user interface" I'd adhere that parameters to the interceptor-ref element is applied to the interceptor on start up and is not stored elsewhere in the configuration manager. This means you can't get this parameters at runtime and only could change via updating and reloading the configuration file struts.xml. If you keep your configuration in the safe place and it's protected from modification then you could make more claims toward your running application safety.

这篇关于struts 2动作没有setter getter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆