日期:2014-05-18  浏览次数:20693 次

struts2显示列表
是把数据库中的user全部打印出来,jsp是这样的
      <s:iterator value="users">
     <s:property value="username"/>
    </s:iterator>
    
    <s:debug></s:debug>
然后Action
public String list() throws Exception{

this.users=this.userService.list();

return "list";
private List<User> users;

public List<User> getUsers() {
return users;
}
public void setUsers(List<User> users) {
this.users = users;
}
然后报错
java.lang.ClassCastException: com.reg.model.User cannot be cast to java.lang.String
at org.apache.struts2.components.Property.start(Property.java:139)
at org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:53)
at org.apache.jsp.listSuccess_jsp._jspx_meth_s_005fproperty_005f0(listSuccess_jsp.java:182)
at org.apache.jsp.listSuccess_jsp._jspx_meth_s_005fiterator_005f0(listSuccess_jsp.java:151)
at org.apache.jsp.listSuccess_jsp._jspService(listSuccess_jsp.java:101)
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:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
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.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:630)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:154)
at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:361)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:265)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:163)