2017-03-14 39 views
1

最近我們修復了struts2的'S2-045'問題。我更新了所有struts2相關jar文件包括freemarker,ognlxWork等。我使用tomcat8來部署我的動態Web項目。在啓動tomcat服務器時沒有任何Exceptions。但一些問題似乎會發生:某些值(從db獲得)應該顯示在jsp頁面上,不會再出現。沒有Exceptions拋出。我也可以看到,我已經在Action Classes中正確地獲得了對象。 在將struts2從2.3.16更新到2.3.32(修復S2-045)後,JSP文件無法解析某些對象的字段


以下是一些例子


// index.jsp ----- here is the list I want to show on the page. 
    // the list is the type of List<News> (Class News is my bussiness Class). 
    // I want to get the 'fTitle' and 'fCreatetime_s' from 'News' but they 
    //  do not show up! (This used to be working very well.) 
    <s:bean name="org.ulibrary.web.Getarclist"> 
     <s:iterator value="list"> 
     <li> 
      <span class="listTitle"> 
       <a target="_blank" href="ViewArc.action? uuid=${UUID}">${fTitle}</a> 
      </span> 
      <span class="listDate">${fCreatetime_s}</span> 
     </li> 
     </s:iterator> 
    </s:bean> 
    //================================================================= 

以下是ralated域ID News.java

// News.java (**just some ralated fields**) 
    class News{ 
     @Id 
     @GeneratedValue(generator = "system-uuid") 
     @GenericGenerator(name = "system-uuid", strategy = "uuid") 
     @Column(name = "f_uuid", length = 32, unique = true) 
     private String UUID; 

     @Column(name = "f_title", length = 200) 
     private String fTitle; 

     @Transient 
     private String fCreatetime_s; 

     public String getUUID() { 
      return UUID; 
     } 
     public void setUUID(String uuid) { 
      UUID = uuid; 
     } 

     public String getFTitle() { 
      return fTitle; 
     } 


     public void setFTitle(String title) { 
      fTitle = title; 
     } 

     public String getFCreatetime_s() { 
      SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
      return formatter.format(Long.valueOf(fCreatetime)); 
     } 


     public void setFCreatetime_s(String createtime_s) { 
      fCreatetime_s = createtime_s; 
     } 
    } 

然後GetarcList.java

//GetarcList.java (just include some related fields) 
    class GetarcList{ 
     private List list; 

     public void setList(List list) { 
      this.list = list; 
     } 

     //!!!!!!$$$$$$$$--- Attention -----$$$$$$$$$!!!!!!!!!!! 
     // this method returns a List<News> , I can successfully get every value of 'News' in the list 
     public List getList() throws AuctionException{ 
      String orderby_str = (String) OrderByMap.get(String.valueOf(orderby)); 
      list = webTagManager.getArcList(row, typeid, titlelen, infolen, orderby_str + " " + orderway); 
      return list; 
     } 

    } 

我想,這也許導致由OGNL或JSP關聯特德jar文件。我在index.jsp或java文件中沒有發現任何問題。

+0

忘了說'UUID'的字段可以在頁面中解析。 –

+0

https://struts.apache.org/docs/struts-23-to-25-migration.html –

回答

1

您需要使用以下格式的getters/setters。只有一個起始小寫字母的屬性不是大寫的。

public String getfTitle() { 
     return fTitle; 
    } 


    public void setfTitle(String title) { 
     fTitle = title; 
    } 
+0

非常感謝,它真的有用。之前我沒有注意到。 –

+0

這個不正確的getter和setter名稱在以前的版本(2.3.16)中是否也有效?或者僅僅是2.3.32版本的一部分。 @Roman我知道我們之前有過關於布爾setter的討論,http://stackoverflow.com/q/36909947/5086633 – yeppe

+1

@yeppe它只受到版本2.3.32的影響,可能在上面。更精確的OGNL版本3.0.11(OgnlRuntime)與Struts2框架捆綁在一起。 –

相關問題