No getter method for property Owner of bean rsArra

问题描述

<%@ page language="java" contentType="text/html;charset=gb2312" %><jsp:directive.page import="com.xsminfo.struts.forms.*" /><%@ page import="java.util.List" %><%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%> <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%><%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%><%@ page import="java.util.LinkedList;" %><% String path = request.getContextPath(); String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";List list=(List)request.getAttribute("rsArray");out.println(list);%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html:html locale="true"> <head> <title>selectInfo.jsp</title> </head> <body><th><a href="<%=basePath %>/selectInfo.jsp"><b>查询</b></a></th><th><a href="" >修改</a></th><th><a href="<%=basePath %>/infoPc.jsp">添加</a></th><th><a href="">删除</a></th></br> <table border="1" > <html:form action="/selectInfo" > <tr> <td width="50%">部门 : <html:text property="departname"/><td/> <td width="50%">使用人 : <html:text property="owner"/><td/><td width="50%">品牌: <html:text property="brand" /><td/><br/></tr><tr><td width="50%">购机时间 : <html:text property="buytime"/><td/><td width="50%">计算机名 : <html:text property="pcname"/><td/><td width="50%">使用人 : <html:text property="username"/><td/></tr><tr><html:submit value="提交"/><html:cancel value="取消"/></tr></html:form></table> <table border="1"> <tr> <td>使用人 :</td><td>内存 : </td><td>电话 : </td><td>特殊软件 : </td><td>机器型号 : </td><td>硬盘 : </td><td>购机时间 : </td><td>计算机名 : </td><td>cpu : <td><td>备注 : <td><td>病毒名称 : <td><td>部门 : <td><td>品牌 : <td><td>使用情况 :<td><td>用户名 : <td><td>是否液晶 : <td><td>光驱 : <td><td>职务 : <td> </tr> <logic:present name="rsArray" scope="request" > <logic:iterate id="rsArray" name="rsArray" > <tr> <td><bean:write name="rsArray" property="owner"/></td> <td><bean:write name="rsArray" property="memory"/></td> <td><bean:write name="rsArray" property="tele"/></td> <td><bean:write name="rsArray" property="specsoft"/></td> <td><bean:write name="rsArray" property="type"/></td> <td><bean:write name="rsArray" property="disksum"/></td> <td><bean:write name="rsArray" property="buytime"/></td> <td><bean:write name="rsArray" property="pcname"/></td> <td><bean:write name="rsArray" property="cpu"/></td> <td><bean:write name="rsArray" property="remark"/></td> <td><bean:write name="rsArray" property="virus"/></td> <td><bean:write name="rsArray" property="departname"/></td> <td><bean:write name="rsArray" property="brand"/></td> <td><bean:write name="rsArray" property="usething"/></td> <td><bean:write name="rsArray" property="username"/></td> <td><bean:write name="rsArray" property="iscrystal"/></td> <td><bean:write name="rsArray" property="ram"/></td> <td><bean:write name="rsArray" property="post"/></td> </tr> </logic:iterate></logic:present> </table> </body></html:html>action public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {SelectInfoForm selectInfoForm = (SelectInfoForm) form;// TODO// Auto-generated// method stubString brand = (String)selectInfoForm.getBrand();String buyTime = (String)selectInfoForm.getBuytime();String departname = (String)selectInfoForm.getDepartname();String owner = (String)selectInfoForm.getOwner();String Pcname = (String)selectInfoForm.getPcname();String username = (String)selectInfoForm.getUsername();System.out.println(brand +"_____________"+buyTime+ "__________"+departname+"________" +owner +"_____"+Pcname+"______________"+username);StringBuffer clause = new StringBuffer("select * from infopc where 1=1 ");if(!brand.equals("")){clause.append("and brand='"+brand+"'");}if(!buyTime.equals("")){clause.append("and buytime='"+buyTime+"'");}if(!departname.equals("")){clause.append("and departname='"+departname+"'");}if(!owner.equals("")){clause.append("and owner='"+owner+"'");}if(!Pcname.equals("")){clause.append("and pcname='"+Pcname+"'");}if(!username.equals("")){clause.append("and username='"+username+"'");}System.out.println("_______sql____________:" + clause);DB db = null;try {db = new DB();db.connDb();ResultSet rs = db.executeQuery(clause.toString());List list= new ArrayList();while(rs.next()) {//System.out.println("____ResultSet have value!___________");//Integer.parseInt(arg0)list.add(rs.getInt(1));list.add(rs.getString(2));list.add(rs.getString(3));list.add(rs.getString(4));list.add(rs.getString(5));list.add(rs.getString(6));list.add(rs.getString(7));list.add(rs.getString(8));list.add(rs.getString(9));list.add(rs.getString(10));list.add(rs.getString(11));list.add(rs.getString(12));list.add(rs.getString(13));list.add(rs.getString(14));list.add(rs.getString(15));list.add(rs.getString(16));list.add(rs.getString(17));list.add(rs.getString(18));list.add(rs.getString(19));System.out.println("rs.getInt(1):"+rs.getInt(1));System.out.println("list.size() :"+list.size());System.out.println(rs.getInt(1)+rs.getString(2));}request.setAttribute("rsArray", list);System.out.println("session_______setAttribute得值是:"+list);System.out.println("____can run here!!!____________");return mapping.findForward("success");} catch (Exception e) {} finally {if (db != null)db.closeDb();}return null;}解决了一个下午 有点迷糊了 问题补充:写了个类 com.xxx.struts.util.Pcinfo 得到新异常。。javax.servlet.ServletException: Cannot find bean Pcinfo in any scopewhile(rs.next()) {//System.out.println("____ResultSet have value!___________");//Integer.parseInt(arg0)list.add(rs.getInt(1));list.add(rs.getString(2));//departlist.add(rs.getString(3));//ownerlist.add(rs.getString(4));//pcnamelist.add(rs.getString(5));//usernamelist.add(rs.getString(6));//postlist.add(rs.getString(7));//brandlist.add(rs.getString(8));//typelist.add(rs.getString(9));//cpulist.add(rs.getString(10));//memlist.add(rs.getString(11));//disksumlist.add(rs.getString(12));//ramlist.add(rs.getString(13));//iscrtylist.add(rs.getString(14));//buytimelist.add(rs.getString(15));//telelist.add(rs.getString(16));//speclist.add(rs.getString(17));//usethinglist.add(rs.getString(18));//viruslist.add(rs.getString(19));//remarkPcinfo ipform= new Pcinfo();ipform.setBrand(rs.getString(7));ipform.setBuytime(rs.getString(14));ipform.setCpu(rs.getString(9));ipform.setDepartname(rs.getString(2));ipform.setDisksum(rs.getString(11));ipform.setIscrystal(rs.getString(13));ipform.setMemory(rs.getString(10));ipform.setOwner(rs.getString(3));ipform.setPcname(rs.getString(4));ipform.setPost(rs.getString(6));ipform.setRam(rs.getString(12));ipform.setRemark(rs.getString(19));ipform.setSpecsoft(rs.getString(16));ipform.setTele(rs.getString(15));ipform.setType(rs.getString(8));ipform.setUsername(rs.getString(5));ipform.setUsething(rs.getString(17));ipform.setVirus(rs.getString(18));list.add(ipform);界面 如下: <logic:present name="rsArray" scope="request" > <logic:iterate id="rsArray" name="Pcinfo" type="com.xsminfo.struts.util.Pcinfo" > <tr> <td><bean:write name="rsArray" property="owner"/></td> <td><bean:write name="rsArray" property="memory"/></td> <td><bean:write name="rsArray" property="tele"/></td> <td><bean:write name="rsArray" property="specsoft"/></td> <td><bean:write name="rsArray" property="type"/></td> <td><bean:write name="rsArray" property="disksum"/></td> <td><bean:write name="rsArray" property="buytime"/></td> <td><bean:write name="rsArray" property="pcname"/></td> <td><bean:write name="rsArray" property="cpu"/></td> <td><bean:write name="rsArray" property="remark"/></td> <td><bean:write name="rsArray" property="virus"/></td> <td><bean:write name="rsArray" property="departname"/></td> <td><bean:write name="rsArray" property="brand"/></td> <td><bean:write name="rsArray" property="usething"/></td> <td><bean:write name="rsArray" property="username"/></td> <td><bean:write name="rsArray" property="iscrystal"/></td> <td><bean:write name="rsArray" property="ram"/></td> <td><bean:write name="rsArray" property="post"/></td> </tr> </logic:iterate></logic:present>.写法不对?

解决方案

你在request中的"rsArray"存放的是一个list这个list里面有许多不同类型的值:getInt,getString.但是取数据的时候却是告诉程序rsArray是有一个JavaBeans的列表,<logic:iterate id="rsArray" name="rsArray" > 并且JavaBean有属性owner<bean:write name="rsArray" property="owner"/>这个是错误的,你需要建立一个RSObject类,将属性存进这个RSObject,并且保证RSObject有下列属性。 <td><bean:write name="rsArray" property="owner"/></td> <td><bean:write name="rsArray" property="memory"/></td> <td><bean:write name="rsArray" property="tele"/></td> <td><bean:write name="rsArray" property="specsoft"/></td> <td><bean:write name="rsArray" property="type"/></td> <td><bean:write name="rsArray" property="disksum"/></td> <td><bean:write name="rsArray" property="buytime"/></td> <td><bean:write name="rsArray" property="pcname"/></td> <td><bean:write name="rsArray" property="cpu"/></td> <td><bean:write name="rsArray" property="remark"/></td> <td><bean:write name="rsArray" property="virus"/></td> <td><bean:write name="rsArray" property="departname"/></td> <td><bean:write name="rsArray" property="brand"/></td> <td><bean:write name="rsArray" property="usething"/></td> <td><bean:write name="rsArray" property="username"/></td> <td><bean:write name="rsArray" property="iscrystal"/></td> <td><bean:write name="rsArray" property="ram"/></td> <td><bean:write name="rsArray" property="post"/></td>
解决方案二:
while(rs.next()) { //System.out.println("____ResultSet have value!___________"); //Integer.parseInt(arg0) list.add(rs.getInt(1)); list.add(rs.getString(2)); list.add(rs.getString(3)); list.add(rs.getString(4)); list.add(rs.getString(5)); list.add(rs.getString(6)); list.add(rs.getString(7)); list.add(rs.getString(8)); list.add(rs.getString(9)); list.add(rs.getString(10)); list.add(rs.getString(11)); list.add(rs.getString(12)); list.add(rs.getString(13)); list.add(rs.getString(14)); list.add(rs.getString(15)); list.add(rs.getString(16)); list.add(rs.getString(17)); list.add(rs.getString(18)); list.add(rs.getString(19)); System.out.println("rs.getInt(1):"+rs.getInt(1)); System.out.println("list.size() :"+list.size()); System.out.println(rs.getInt(1)+rs.getString(2)); } 你在这里给list添加值 就想楼上说的 你没有给他放到一个Bean里 就是一个对象了 所以你就不能用<bean:write >了 你直接用EL输出一下${rsArray} 就行了 如果想哪么写就定义个对象 while(rs.next()) { //System.out.println("____ResultSet have value!___________"); // 对象 Obj obj = new Obj(); // 给对象赋值 从数据库中取出来的值 obj.setName(rs.getInt(1)); // 添加到集合中 list.add(obj); } 现在就保存到对象中了 就可以用<bean:write> 了

时间: 2024-10-22 13:31:12

No getter method for property Owner of bean rsArra的相关文章

Struts常见错误汇总

1."No bean found under attribute key XXX" 在struts-config.xml里定义了一个ActionForm,但type属性指定的类不存在,type属性的值应该是Form类的全名.或者是,在Action的定义中,name或attribute属性指定的ActionForm不存在. 2."Cannot find bean XXX in any scope" 在Action里一般会request.setAttribute()一些

[java] javax.el.PropertyNotFoundException: Property &amp;#39;id&amp;#39; not found on type bean.Student

问题提出: 在使用MyEclipse开发Java Web时,调用DAO和Java Bean出现了如下错误: 严重: Servlet.service() for servlet [jsp] in context with path [/JDBCbyDao] threw exception [An exception occurred processing JSP page /student.jsp at line 3734: 35: <c:forEach items="${ studentL

spring无法装载bean的属性

问题描述 各位好, 我有一spring mvc + hibernate + spring的项目. 实体: /** * Created by IntelliJ IDEA. * User: smart * Date: 2010-9-16 * Time: 12:35:05 */ public class DictData { private Long id; private String code; private String name; private String father; //gette

javabean-java注入bean的相关问题,求大神帮我看看,感激不尽!急急急。。。。。。

问题描述 java注入bean的相关问题,求大神帮我看看,感激不尽!急急急...... 启动tomcat后报错了严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListenerorg.springframework.beans.factory.BeanCreationException: Error

Spring 使用注解装配Bean

Spring可以使用xml配置文件来装配bean,也可以使用注解来装配Bean 1.在上一篇文章的基础上在com.springtest包中新建Tire类,源码为: package com.springtest; public class Tire { privatedouble price; privateString brand; publicString getBrand() { returnbrand; } publicvoid setBrand(String brand) { this.

深入解析Java的Spring框架中bean的依赖注入_java

每一个基于java的应用程序都有一个共同工作来展示给用户看到的内容作为工作的应用几个对象.当编写一个复杂的Java应用程序,应用程序类应该尽可能独立其他Java类来增加重复使用这些类,并独立于其他类别的测试它们,而这样做单元测试的可能性.依赖注入(或有时称为布线)有助于粘合这些类在一起,同时保持他们的独立. 考虑有其中有一个文本编辑器组件的应用程序,要提供拼写检查.标准的代码将看起来像这样:   public class TextEditor { private SpellChecker spe

Map 与 Java Bean 之间的互换

通过反射实现 过程并无甚复杂,通过反射实现接口.首先当然是遍历一下这些集合,无论 Map 还是 Bean. /** * Bean 转换为 Map * @param obj * @return */ public static Map<String, Object> bean2map(Object obj) { if (obj == null) return null; Map<String, Object> map = new HashMap<>(); for (Met

在系统中使用Bean Validation验证参数

为什么要使用Bean Validation?  当我们实现某个接口时,都需要对入参数进行校验.例如下面的代码 public String queryValueByKey(String parmTemplateCode, String conditionName, String conditionKey, String resultName) { checkNotNull(parmTemplateCode, "parmTemplateCode not null"); checkNotNu

spring入门(8) 装配Bean之自动装配

Spring_Autowiring collaborators 在Spring3.2.2中自动装配类型,分别为:no(default)(不采用自动装配). byName,byType,constructor下面来分别介绍一下这些是如何自动装配的 <bean id="foo" class="...Foo" autowire="autowire type"> Mode            Explanation no: (Default