java.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.String

來源:互聯網
上載者:User

這個問題因為我在今天使用iterator迭代輸出值得時候,發現使用單字元的

<table border="1" width="300"><s:iterator var="bb" value="{'1','2','3','4','5'}"><tr><td><s:property value="bb"/></td></tr></s:iterator>

java.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.String
 at org.apache.struts2.components.Property.start(Property.java:159)
 at org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:53)
 at org.apache.jsp.s_002diterator_002dlist_jsp._jspx_meth_s_005fproperty_005f0(s_002diterator_002dlist_jsp.java:173)
 at org.apache.jsp.s_002diterator_002dlist_jsp._jspx_meth_s_005fiterator_005f0(s_002diterator_002dlist_jsp.java:142)
 at org.apache.jsp.s_002diterator_002dlist_jsp._jspService(s_002diterator_002dlist_jsp.java:80)
 at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
 at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
 at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:426)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
 at java.lang.Thread.run(Thread.java:722)

如果我們寫數組元素時使用的單字元比如:a、b、c、d、e、f、g這樣的單字元系統會當做字元處理所以不能這樣

解決的辦法:

1、使用雙引號,外層改成單引號

<s:iterator var="bb" value='{"1","2","3"}'><tr><td><s:property value="bb"/></td></tr></s:iterator>

2、在現實內容哪裡value變數對象+#

<s:iterator var="bb" value="{'a','b'}"><tr><td><s:property value="#bb"/></td></tr></s:iterator>

3、使用系統預設

<s:iterator var="bb" value="{'a','b'}"><tr><td><s:property/></td></tr></s:iterator>

參考網址:

http://blog.csdn.net/chch010520/article/details/7423143



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.