在TestBooDBean2.jsp中通过setProperty设置bean0的属性值为aaa,为何getProperty获取的值为null?
代码入下:
TestBookDBean2.jsp:
  
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.util.*,bookstore.*;" %>
<html>
<head>
<title>
TestBookDBean2
</title>
</head>
<body bgcolor="#ffffff">
<jsp:useBean id="book0" scope="session" class="bookstore.BookBean"/>
<jsp:setProperty name="book0" property="bookcocern" value="aaa" />
<P>bookcocern的值为:<jsp:getProperty name="book0" property="bookcocern"/>
</p>
</body>
</html>
 
BookBean.java:package bookstore;
public class BookBean
{
    private int id;
    private String title;
    private String author;
    private String bookcocern;
    private String publish_date;
    private float price;
    private int amount;
    private String re;
    public BookBean()
    {
    }
    public BookBean (int id,String title,String author,String boobkcocern,String publish_date,float price,int amount,String re)
    {
       this.id=id;
       this.title=title;
       this.author=author;
       this.bookcocern=bookcocern;
       this.publish_date=publish_date;
       this.price=price;
       this.amount=amount;
       this.re=re;
    }
    public int getId()
    {
        return id;
    }
    public String getTitle()
    {
         return title;
    }
    public String getAuthor()
   {
         return author;
   }
   public String getBookcocern()
   {
     return bookcocern;
   }
   public String  getPublish_date()
   {
        return publish_date;
   }
   public float getPrice()
   {
        return price;
   }
   public int getAmount()
  {
     return amount;
  }
  public String getRe()
  {
         return re;
  }
  public void setId(int id)
  {
       this.id=id;
  }
  public void setTitle(String title)
  {
       this.title=title;
  }
  public void setAuthor(String author)
  {
       this.author=author;
  }
  public void setBookcocern(String bookconcern)
  {
      this.bookcocern=bookcocern;
  }
  public void setPublish_date(String publish_date)
  {
       this.publish_date=publish_date;
  }
  public void setPrice(int price)
  {
       this.price=price;
  }
 /* public static void main(String args[])
  {
      BookBean b1=new BookBean(1,"rrr","ccc","ddd","2005-3-5",258,58,"fff");
      System.out.println(b1.getAmount());
      System.out.println(b1.getPrice());
  }*/
}

解决方案 »

  1.   

    我把你的代码精简了一下.如下所示.没有问题.你去测试一下,是不是还其它的错误 .
    <%@ page contentType="text/html; charset=GBK" %>
    <html>
    <head>
    <title>
    TestBookDBean2
    </title>
    </head>
    <body bgcolor="#ffffff">
    <jsp:useBean id="book0" scope="session" class="com.bookstore.BookBean"/>
    <jsp:setProperty name="book0" property="bookcocern" value="aaa" />
    <P>bookcocern的值为:<jsp:getProperty name="book0" property="bookcocern"/></p>
    </body>
    </html>package com.bookstore;public class BookBean {
        private String bookcocern; public String getBookcocern() {
    return bookcocern;
    } public void setBookcocern(String bookcocern) {
    this.bookcocern = bookcocern;
    }}
      

  2.   

    这两句<jsp:useBean id="book0" scope="session" class="bookstore.BookBean"/>
    <jsp:setProperty name="book0" property="bookcocern" value="aaa" />
    是不是应该写成<jsp:useBean id="book0" scope="session" class="bookstore.BookBean">
       <jsp:setProperty name="book0" property="bookcocern" value="aaa" />
    </jsp:useBean>
      

  3.   

    lz将javabean代码修改如下:(lz需要知道对一个javabean的要求)package bookstore;public class BookBean {
    private int id;
    private String title;
    private String author;
    private String bookcocern;
    private String publish_date;
    private float price;
    private int amount;
    private String re; public BookBean() {

    } public int getAmount() {
    return amount;
    } public void setAmount(int amount) {
    this.amount = amount;
    } public String getAuthor() {
    return author;
    } public void setAuthor(String author) {
    this.author = author;
    } public String getBookcocern() {
    return bookcocern;
    } public void setBookcocern(String bookcocern) {
    this.bookcocern = bookcocern;
    } public int getId() {
    return id;
    } public void setId(int id) {
    this.id = id;
    } public float getPrice() {
    return price;
    } public void setPrice(float price) {
    this.price = price;
    } public String getPublish_date() {
    return publish_date;
    } public void setPublish_date(String publish_date) {
    this.publish_date = publish_date;
    } public String getRe() {
    return re;
    } public void setRe(String re) {
    this.re = re;
    } public String getTitle() {
    return title;
    } public void setTitle(String title) {
    this.title = title;
    }
    }
      

  4.   

    为什么我用setProperty传值,getProperty的值为null呢?求指教