Struts參數名稱的Bug

 

Struts參數名稱的Bug

 

 

          應用Struts架構的web程序員越來越多,但不知道你們是否遇到過,在寫jsp頁面時,需要提交到表單中的參數名並不是所有的名字都可取。

          之前,基於struts寫得jsp頁面,應該不算少了,一直沒有遇到,直到昨天,修改一個別人程序裏的bug,調試了半天,發現,原來struts對有些參數名稱的處理有問題。

<logic:iterate id="view" name="compensationBalanceForm" property="listChunk.collection" indexId="index"              type="com.neusoft.ehr.business.compensation.balance.BalanceViewVO" >
    <tr class="<%=(index.intValue() % 2 == 0) ? "alternateA" : "alternateB"%>">
      <td nowrap><bean:write name="view" property="employeeCode"/></td>
      <td nowrap><bean:write name="view" property="employeeName"/></td>
      <td nowrap><bean:write name="view" property="year"/></td>
      <td nowrap><html:text name="view" property="value" οnchange="javascript:changeValue   (this.value)" /></td>
      <td>
       <a href="javascript:viewUpdate(<bean:write name="view" property="oid"/>)">
           <bean:message bundle="compensation" key="cb.policy.edit.editMode.replace"/>
       </a>
      </td>
    </tr>
</logic:iterate>

上面這段代碼在提交時,就會出現問題,系統運行在struts處理時就出了問題,根本到不了我們自己的系統就停了 。org.apache.commons.beanutils.BeanUtils 類在處理參數時出現了問題。

下面是該jsp文件編譯後的java文件對應部分代碼:

private boolean _jspx_meth_html_text_5(javax.servlet.jsp.tagext.Tag _jspx_th_logic_iterate_0, javax.servlet.jsp.PageContext pageContext)
          throws Throwable {
    JspWriter out = pageContext.getOut();
    /* ----  html:text ---- */
    org.apache.struts.taglib.html.TextTag _jspx_th_html_text_5 = (org.apache.struts.taglib.html.TextTag) _jspx_tagPool_html_text_property_onchange_name.get(org.apache.struts.taglib.html.TextTag.class);
    _jspx_th_html_text_5.setPageContext(pageContext);
    _jspx_th_html_text_5.setParent(_jspx_th_logic_iterate_0);
    _jspx_th_html_text_5.setName("view");
    _jspx_th_html_text_5.setProperty("value");
    _jspx_th_html_text_5.setOnchange("javascript:changeValue(this.value)");
    int _jspx_eval_html_text_5 = _jspx_th_html_text_5.doStartTag();
    if (_jspx_th_html_text_5.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE)
      return true;
    _jspx_tagPool_html_text_property_onchange_name.reuse(_jspx_th_html_text_5);
    return false;
  }

運行時,後提示Property : "value"  has not set Method  !!!       從表面看不應該有錯誤。如果我們在這裏將value 修改爲其他名字,比如  "valueSecond" ,並修改相應業務方法後,從新運行系統,一切正常了。這就是strut在組裝表單時,對參數名爲“value”的處理的不正確。

希望大家看了後不要再來這裏浪費時間調試!!!

[email protected] 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章