這個問題因為我在今天使用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