• <bdo id='mTsRQ'></bdo><ul id='mTsRQ'></ul>

      <small id='mTsRQ'></small><noframes id='mTsRQ'>

      1. <tfoot id='mTsRQ'></tfoot>
        <i id='mTsRQ'><tr id='mTsRQ'><dt id='mTsRQ'><q id='mTsRQ'><span id='mTsRQ'><b id='mTsRQ'><form id='mTsRQ'><ins id='mTsRQ'></ins><ul id='mTsRQ'></ul><sub id='mTsRQ'></sub></form><legend id='mTsRQ'></legend><bdo id='mTsRQ'><pre id='mTsRQ'><center id='mTsRQ'></center></pre></bdo></b><th id='mTsRQ'></th></span></q></dt></tr></i><div id='mTsRQ'><tfoot id='mTsRQ'></tfoot><dl id='mTsRQ'><fieldset id='mTsRQ'></fieldset></dl></div>
      2. <legend id='mTsRQ'><style id='mTsRQ'><dir id='mTsRQ'><q id='mTsRQ'></q></dir></style></legend>

        在'class xxx上设置'xxx'时出现意外异常:错误设置表达式'xxx'的

        时间:2023-09-25
          • <bdo id='SF99a'></bdo><ul id='SF99a'></ul>

              <tbody id='SF99a'></tbody>
            1. <small id='SF99a'></small><noframes id='SF99a'>

                <tfoot id='SF99a'></tfoot>
                <i id='SF99a'><tr id='SF99a'><dt id='SF99a'><q id='SF99a'><span id='SF99a'><b id='SF99a'><form id='SF99a'><ins id='SF99a'></ins><ul id='SF99a'></ul><sub id='SF99a'></sub></form><legend id='SF99a'></legend><bdo id='SF99a'><pre id='SF99a'><center id='SF99a'></center></pre></bdo></b><th id='SF99a'></th></span></q></dt></tr></i><div id='SF99a'><tfoot id='SF99a'></tfoot><dl id='SF99a'><fieldset id='SF99a'></fieldset></dl></div>
              • <legend id='SF99a'><style id='SF99a'><dir id='SF99a'><q id='SF99a'></q></dir></style></legend>

                  本文介绍了在'class xxx上设置'xxx'时出现意外异常:错误设置表达式'xxx'的值['x',]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我通过查询字符串将一些参数传递给实现 ModelDriven 的动作类.

                  I'm passing some parameters to an action class implementing ModelDriven<Transporter> through a query-string.

                  <s:form namespace="/admin_side" action="Test" id="dataForm" name="dataForm">
                      <s:url id="editURL" action="EditTest" escapeAmp="false">
                          <s:param name="transporterId" value="1"/>
                          <s:param name="transporterName" value="'DHL'"/>
                      </s:url>
                      <s:a href="%{editURL}">Click</s:a>
                  </s:form>
                  

                  动作类如下.

                  @Namespace("/admin_side")
                  @ResultPath("/WEB-INF/content")
                  @ParentPackage(value = "struts-default")
                  public final class TestAction extends ActionSupport 
                                             implements Serializable, Preparable, ModelDriven<Transporter>
                  {
                      private static final long serialVersionUID = 1L;
                      private Transporter transporter = new Transporter();
                  
                      @Action(value = "Test",
                      results = {
                          @Result(name = ActionSupport.SUCCESS, location = "Test.jsp"),
                          @Result(name = ActionSupport.INPUT, location = "Test.jsp")},
                      interceptorRefs = {
                          @InterceptorRef(value = "paramsPrepareParamsStack", 
                                   params = {"params.acceptParamNames", "transporterId, transporterName"})})
                      public String load() throws Exception {
                          return ActionSupport.SUCCESS;
                      }
                  
                      @Action(value = "EditTest",
                      results = {
                          @Result(name = ActionSupport.SUCCESS, location = "Test.jsp"),
                          @Result(name = ActionSupport.INPUT, location = "Test.jsp")},
                      interceptorRefs = {
                          @InterceptorRef(value = "paramsPrepareParamsStack", 
                                   params = {"params.acceptParamNames", "transporterId, transporterName"})})
                      public String edit() {
                          System.out.println(transporter.getTransporterId() 
                                           + " : " + transporter.getTransporterName());
                          return ActionSupport.SUCCESS;
                      }
                  
                      @Override
                      public Transporter getModel() {
                          return transporter;
                      }
                  
                      @Override
                      public void prepare() throws Exception {}
                  }
                  

                  服务器终端显示以下消息.

                  The server terminal displays the following messages.

                  Jan 09, 2014 4:06:32 PM com.opensymphony.xwork2.interceptor.ParametersInterceptor error
                  SEVERE: Developer Notification (set struts.devMode to false to disable this message):
                  Unexpected Exception caught setting 'transporterId' on 'class actions.TestAction: Error setting expression 'transporterId' with value ['1', ]
                  Jan 09, 2014 4:06:32 PM com.opensymphony.xwork2.interceptor.ParametersInterceptor error
                  SEVERE: Developer Notification (set struts.devMode to false to disable this message):
                  Unexpected Exception caught setting 'transporterName' on 'class actions.TestAction: Error setting expression 'transporterName' with value ['DHL', ]
                  

                  即使日志级别是 SEVERE,这些参数的值在操作类中也可以作为

                  Even though the log level is SEVERE, the values of these parameters are available in the action class as

                  System.out.println(transporter.getTransporterId() 
                                   + " : " + transporter.getTransporterName());
                  

                  edit() 方法中.

                  如果 paramsPrepareParamsStackdefaultStack 替换,那么这些消息就会消失.

                  If paramsPrepareParamsStack is replaced by defaultStack then, these messages disappear.

                  ['DHL', ] 这样的表达式表示一个数组.模型中的 transporterIdtransporterName 分别是 LongString 类型.

                  Expressions like ['DHL', ] indicate an array. transporterId and transporterName in the model are, however of type Long and String respectively.

                  我做错了什么?

                  推荐答案

                  这里不涉及数组问题(即使看起来像那样):这种异常意味着Struts找不到你的参数的Setter:

                  No array problem is involved here (even if it seems like that): this kind of exception means that Struts can't find a Setter for your parameter:

                  来自 ParametersInterceptor 文档:

                  缺少参数的警告

                  当给定参数名称没有设置器时,会出现警告消息像下面这样会在 devMode 下登录:

                  When there is no setter for given parameter name, a warning message like below will be logged in devMode:

                  SEVERE: Developer Notification (set struts.devMode to false to disable this 
                  message):
                  Unexpected Exception caught setting 'search' on 'class demo.ItemSearchAction: 
                  Error setting expression 'search' with value ['search', ]
                  Error setting expression 'search' with value ['search', ] - [unknown location] 
                    at com.opensymphony.xwork2.ognl.OgnlValueStack.handleRuntimeException(OgnlValueStack.java:201)
                    at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:178)
                    at com.opensymphony.xwork2.ognl.OgnlValueStack.setParameter(OgnlValueStack.java:152)
                  

                  因此是允许开发人员发现缺少的 setter 的预期行为或参数名称或设置器中的拼写错误.

                  Thus is expected behaviour to allow developer to spot missing setter or typo in either parameter name or setter.

                  您可以通过在 JSP 中放入 Action 中不存在的元素来轻松重现此错误.

                  You can easily reproduce this error by putting an element in JSP that does not exist in the Action.

                  由于模型中存在您的属性(及其设置器),并且您正在使用 ModelDrivenparamsPrepareParamsStack,我认为正在发生的事情是:

                  Since your properties exist (with their Setters) in the Model, and you are using ModelDriven and paramsPrepareParamsStack, what I think is going on is:

                  • ModelDriven Interceptor被委托处理Model对象;
                  • 第一次调用ParametersInterceptorModelDrivenInterceptor还没有运行;
                  • 那么您的 Action 对 Model 对象一无所知,并尝试在 Action 中而不是在 Model 中查找参数的 Setter.
                  • 第二个拦截器在 ModelDriven 之后运行,并且确切地知道在哪里设置参数.这就是您在 Action 方法中正确设置参数的原因.
                  • ModelDriven Interceptor is delegated to handle the Model object;
                  • The first time you call Parameters Interceptor, ModelDriven Interceptor has not run yet;
                  • Then your Action knows nothing about the Model object, and try to find the Setters for your parameters in the Action, NOT in the Model.
                  • The second interceptor instead runs after the ModelDriven one, and knows exactly where to set the parameters. This is why you have the parameters correctly set in the Action method.

                  但如果这是真的,那么您应该能够在 prepare() 方法中检索这些参数(这就是您使用此堆栈的原因...):
                  请尝试,并在此处发布结果.

                  But if this is true, then you should NOT be able to retrieve those parameters in the prepare() method (that is the reason you are using this stack...):
                  please try, and post here the result.

                  我想到解决这个问题的第一件事是将 ModelDriven Interceptor 放在第一个 Parameters Interceptor 之前(通过复制或移动它,我不确定它会在这两种情况下产生哪种副作用,如果有的话,你应该再次尝试并在此处报告).

                  The first thing that comes to my mind to resolve this issue, is to place the ModelDriven Interceptor before the first Parameters Interceptor (by either copying it, or by moving it, I'm not sure which kind of side effect, if any, it could produce in both cases, you should again try and reporting it here).

                  然后定义下面的堆栈,并使用它.

                  Then define the following stack, and use it.

                  <interceptor-stack name="modelParamsPrepareParamsStack">
                      <interceptor-ref name="exception"/>
                      <interceptor-ref name="alias"/>
                      <interceptor-ref name="i18n"/>
                      <interceptor-ref name="checkbox"/>
                      <interceptor-ref name="multiselect"/>
                  
                      <!-- NEW ModelDriven Position -->
                      <interceptor-ref name="modelDriven"/>
                  
                      <interceptor-ref name="params">
                          <param name="excludeParams">^dojo..*,^struts..*,^session..*,^request..*,^application..*,^servlet(Request|Response)..*,^parameters..*,^action:.*,^method:.*</param>
                      </interceptor-ref>
                      <interceptor-ref name="servletConfig"/>
                      <interceptor-ref name="prepare"/>
                      <interceptor-ref name="chain"/>
                  
                      <!-- OLD ModelDriven Position -->
                      <!--interceptor-ref name="modelDriven"/-->
                  
                      <interceptor-ref name="fileUpload"/>
                      <interceptor-ref name="staticParams"/>
                      <interceptor-ref name="actionMappingParams"/>
                      <interceptor-ref name="params">
                          <param name="excludeParams">^dojo..*,^struts..*,^session..*,^request..*,^application..*,^servlet(Request|Response)..*,^parameters..*,^action:.*,^method:.*</param>
                      </interceptor-ref>
                      <interceptor-ref name="conversionError"/>
                      <interceptor-ref name="validation">
                          <param name="excludeMethods">input,back,cancel,browse</param>
                      </interceptor-ref>
                      <interceptor-ref name="workflow">
                          <param name="excludeMethods">input,back,cancel,browse</param>
                      </interceptor-ref>
                  </interceptor-stack>
                  

                  希望对您有所帮助.

                  这篇关于在'class xxx上设置'xxx'时出现意外异常:错误设置表达式'xxx'的值['x',]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:“找不到 Struts 调度程序"在 WebLogic 12.1.3 上部署应用程序时出错 下一篇:通过 Struts 2 中的 ModelDriven 将参数传递给动作

                  相关文章

                  <tfoot id='60rrp'></tfoot>

                    <legend id='60rrp'><style id='60rrp'><dir id='60rrp'><q id='60rrp'></q></dir></style></legend>

                      <bdo id='60rrp'></bdo><ul id='60rrp'></ul>
                    <i id='60rrp'><tr id='60rrp'><dt id='60rrp'><q id='60rrp'><span id='60rrp'><b id='60rrp'><form id='60rrp'><ins id='60rrp'></ins><ul id='60rrp'></ul><sub id='60rrp'></sub></form><legend id='60rrp'></legend><bdo id='60rrp'><pre id='60rrp'><center id='60rrp'></center></pre></bdo></b><th id='60rrp'></th></span></q></dt></tr></i><div id='60rrp'><tfoot id='60rrp'></tfoot><dl id='60rrp'><fieldset id='60rrp'></fieldset></dl></div>

                      <small id='60rrp'></small><noframes id='60rrp'>