在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());
}*/
}
代码入下:
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());
}*/
}
解决方案 »
- Jsp页面打印
- 购物车运行The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request
- 请问:用JS如何关闭窗口.
- 跪求JSP开发网站流程
- 不用Sql语句,用循环语句,可以去掉重复记录吗?
- 关于翻页乱码问题(100分)
- 当我打开第一个结果集后,循环得到记录,并根据这个,打开第二个结果集.这样可以吗?帮我看看.谢了
- 急,为什么从数据库读数据老出现下面的情况?
- 新手求救,怎样判断查询结果为空啊???急
- 单例探讨
- 关于JSP图片管理
- jsp关于获取当前url的问题
<%@ 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;
}}
<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>
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;
}
}