提示:
An error occurred at line: 18 in the jsp file: /insertData.jsp
Generated servlet error:
C:\Tomcat 5.0\work\Catalina\localhost\Myjsp\org\apache\jsp\insertData_jsp.java:89: cannot resolve symbol
symbol : variable BookId
location: class org.apache.jsp.insertData_jsp
database.executeQuery("insert into t_book values('"+BookId+"','"+BookName+"','"+BookAuthor+"','"+BookPress+"','"+BookPrice+"','"+BookDate+"')");
共有六处错误,也就是六个参数传递的问题
showData.jsp代码如下:
<%@ page language="java" import="java.sql.*" contentType="text/html;charset=GBK" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=GBK">
<title>JavaBean访问数据库</title>
</head>
<body>
<p><b><div align=center>图书目录</b></p>
<jsp:useBean id="database" scope="session" class="hunan.JDBCBean"/>
<table border=1 cellpading=10>
<tr>
<th aligh=center>编号</th>
<th aligh=center>书名</th>
<th aligh=center>作者</th>
<th aligh=center>出版社</th>
<th aligh=center>价格</th>
<th aligh=center>出版日期</th>
</tr>
<%
ResultSet RS=database.executeQuery("select * from t_book");
while(RS.next())
{
out.print("<tr>");
out.print("<td>"+RS.getString("book_id")+"</td>");
out.print("<td>"+RS.getString("book_name")+"</td>");
out.print("<td>"+RS.getString("book_author")+"</td>");
out.print("<td>"+RS.getString("book_press")+"</td>");
out.print("<td>"+RS.getFloat("book_price")+"</td>");
out.print("<td>"+RS.getString("book_date").substring(0,10)+"</td>");
out.print("</tr>");
//注意数据类型
}
out.print("</table>");
RS.close();
%>
<br><br><br><hr>
<FORM action="insertData.jsp" method=post>
<p>编号:<INPUT type=text size=10 name="BookId">
书名:<INPUT type=text size=10 name="BookName">
作者:<INPUT type=text size=10 name="BookAuthor">
出版社:<INPUT type=text size=10 name="BookPress">
定价:<INPUT type=text size=10 name="BookPrice">
出版日期(如02/29/2000):<INPUT type=text size=10 name="BookDate"></p>
<INPUT type="submit" value="送出" name=submit1>
<INPUT type="reset" value="清除" name=reset1>
</body>
</html>
insertData.jsp代码如下:
<%@ page language="java" import="java.sql.*" contentType="text/html;charset=GBK" %>
<html>
<head>
<title>插入信息</title>
<head>
<body>
<jsp:useBean id="bookdata" scope="session" class="hunan.BookData"/>
<jsp:setProperty name="bookdata" property="BookId"/>
<jsp:setProperty name="bookdata" property="BookName"/>
<jsp:setProperty name="bookdata" property="BookAuthor"/>
<jsp:setProperty name="bookdata" property="BookPress"/>
<jsp:setProperty name="bookdata" property="BookPrice"/>
<jsp:setProperty name="bookdata" property="BookDate"/>
<jsp:useBean id="database" scope="session" class="hunan.JDBCBean"/>
<%
database.executeQuery("insert into t_book values('"+BookId+"','"+BookName+"','"+BookAuthor+"','"+BookPress+"','"+BookPrice+"','"+BookDate+"')");
%>
<p><b><div align=center>数据已经成功插入</b></p>
<a href="showData.jsp" align=center>返 回</a>
</body>
</html>
BookData.java代码如下:
package hunan;
public class BookData
{
private String BookId ="";
private String BookName ="";
private String BookAuthor ="";
private String BookPress ="";
private String BookPrice ="";
private String BookDate ="";
public BookData()
{
}
public void setBookId(String BookId)
{
this.BookId=BookId;
}
public void setBookName(String BookName)
{
this.BookName=BookName;
}
public void setBookAuthor(String BookAuthor)
{
this.BookAuthor=BookAuthor;
}
public void setBookPress(String BookPress)
{
this.BookPress=BookPress;
}
public void setBookPrice(String BookPrice)
{
this.BookPrice=BookPrice;
}
public void setBookDate(String BookDate)
{
this.BookDate=BookDate;
}
public String getBookId()
{
return this.BookId;
}
public String getBookName()
{
return this.BookName;
}
public String getBookAuthor()
{
return this.BookAuthor;
}
public String getBookPress()
{
return this.BookPress;
}
public String getBookPrice()
{
return this.BookPrice;
}
public String getBookDate()
{
return this.BookDate;
}
}
OS:我用内置对象request的getParameter()方法可以实现,但是我换用<jsp:setProperty>就不可以了,不知道为什么,showData.jsp没有问题,错误是在调用insertData.jsp时出现的,
而且,去掉insertData.jsp里的SQL语句,我用<jsp:getProperty>显示参数信息时,提示
Cannot find any information on property 'BookId' in a bean of type 'hunan.BookData'
请高手指点
8 个解决方案
#1
你把javabean中private String BookId ="";
private String BookName ="";
private String BookAuthor ="";
private String BookPress ="";
private String BookPrice ="";
private String BookDate ="";
和JSP页面中的Book全部改为小写b就可以了
private String BookName ="";
private String BookAuthor ="";
private String BookPress ="";
private String BookPrice ="";
private String BookDate ="";
和JSP页面中的Book全部改为小写b就可以了
#2
javabean中的属性命名是有规定的
把b全改为小写的吧。
把b全改为小写的吧。
#3
up
#4
应该把showData.jsp中的
while(RS.next())
{
out.print("<tr>");
out.print("<td>"+RS.getString("book_id")+"</td>");
out.print("<td>"+RS.getString("book_name")+"</td>");
out.print("<td>"+RS.getString("book_author")+"</td>");
out.print("<td>"+RS.getString("book_press")+"</td>");
out.print("<td>"+RS.getFloat("book_price")+"</td>");
out.print("<td>"+RS.getString("book_date").substring(0,10)+"</td>");
out.print("</tr>");
//注意数据类型
}
的book_id,book_name,...改为的‘b’改为大写,会快一点吧,因为你数据库里面都是大写的,你这样当然是错了!
while(RS.next())
{
out.print("<tr>");
out.print("<td>"+RS.getString("book_id")+"</td>");
out.print("<td>"+RS.getString("book_name")+"</td>");
out.print("<td>"+RS.getString("book_author")+"</td>");
out.print("<td>"+RS.getString("book_press")+"</td>");
out.print("<td>"+RS.getFloat("book_price")+"</td>");
out.print("<td>"+RS.getString("book_date").substring(0,10)+"</td>");
out.print("</tr>");
//注意数据类型
}
的book_id,book_name,...改为的‘b’改为大写,会快一点吧,因为你数据库里面都是大写的,你这样当然是错了!
#5
补充一点,我在数据库里的表项是book_id,book_name,这里的BookName等是我的临时变量,传递参数用的,我在用request.getParameter()时参数传递没有问题,也就是说showData.jsp没有错
我的同事给我的例子里,private String User为大写,这里采用大写主要考虑getBookName()方法的命名规律,(开头小写,以后每个单词都大写开头,:))
不过我会一试的,多谢
我的同事给我的例子里,private String User为大写,这里采用大写主要考虑getBookName()方法的命名规律,(开头小写,以后每个单词都大写开头,:))
不过我会一试的,多谢
#6
public class TestBean
{
private int userId;
private String userName;
public int getUserId()
{
return userId;
}
public void setUserId(int userId)
{
this.userId=userId;
}
public String getUserName()
{
return userName;
}
public void setUserName(String userName)
{
this.userName=userName;
}
}
这样才符合JavaBean属性的命名规范,叫做getter和setter方法。
{
private int userId;
private String userName;
public int getUserId()
{
return userId;
}
public void setUserId(int userId)
{
this.userId=userId;
}
public String getUserName()
{
return userName;
}
public void setUserName(String userName)
{
this.userName=userName;
}
}
这样才符合JavaBean属性的命名规范,叫做getter和setter方法。
#7
多谢各位好意,规范的问题我会注意的,但是问题解决阿,那有什么用,期待达淫中.....
#8
问题解决:
String bookId=request.getParameter("bookId");
String bookName=request.getParameter("bookName");
bookName=new String(bookName.getBytes("ISO-8859-1"),"GBK");
String bookAuthor=request.getParameter("bookAuthor");
bookAuthor=new String(bookAuthor.getBytes("ISO-8859-1"),"GBK");
String bookPress=request.getParameter("bookPress");
bookPress=new String(bookPress.getBytes("ISO-8859-1"),"GBK");
String bookPrice=request.getParameter("bookPrice");
String bookDate=request.getParameter("bookDate");
添加如上代码,主要是SQL语句用到的变量要声明,以及中文编码解决。
还是感谢各位的支持,实际上不用以下代码
<jsp:useBean id="bookdata" scope="session" class="hunan.BookData"/>
<jsp:setProperty name="bookdata" property="bookId"/>
<jsp:setProperty name="bookdata" property="bookName"/>
<jsp:setProperty name="bookdata" property="bookAuthor"/>
<jsp:setProperty name="bookdata" property="bookPress"/>
<jsp:setProperty name="bookdata" property="bookPrice"/>
<jsp:setProperty name="bookdata" property="bookDate"/>
也可以实现,这就是我说的用request的getParameter()方法。
String bookId=request.getParameter("bookId");
String bookName=request.getParameter("bookName");
bookName=new String(bookName.getBytes("ISO-8859-1"),"GBK");
String bookAuthor=request.getParameter("bookAuthor");
bookAuthor=new String(bookAuthor.getBytes("ISO-8859-1"),"GBK");
String bookPress=request.getParameter("bookPress");
bookPress=new String(bookPress.getBytes("ISO-8859-1"),"GBK");
String bookPrice=request.getParameter("bookPrice");
String bookDate=request.getParameter("bookDate");
添加如上代码,主要是SQL语句用到的变量要声明,以及中文编码解决。
还是感谢各位的支持,实际上不用以下代码
<jsp:useBean id="bookdata" scope="session" class="hunan.BookData"/>
<jsp:setProperty name="bookdata" property="bookId"/>
<jsp:setProperty name="bookdata" property="bookName"/>
<jsp:setProperty name="bookdata" property="bookAuthor"/>
<jsp:setProperty name="bookdata" property="bookPress"/>
<jsp:setProperty name="bookdata" property="bookPrice"/>
<jsp:setProperty name="bookdata" property="bookDate"/>
也可以实现,这就是我说的用request的getParameter()方法。
#1
你把javabean中private String BookId ="";
private String BookName ="";
private String BookAuthor ="";
private String BookPress ="";
private String BookPrice ="";
private String BookDate ="";
和JSP页面中的Book全部改为小写b就可以了
private String BookName ="";
private String BookAuthor ="";
private String BookPress ="";
private String BookPrice ="";
private String BookDate ="";
和JSP页面中的Book全部改为小写b就可以了
#2
javabean中的属性命名是有规定的
把b全改为小写的吧。
把b全改为小写的吧。
#3
up
#4
应该把showData.jsp中的
while(RS.next())
{
out.print("<tr>");
out.print("<td>"+RS.getString("book_id")+"</td>");
out.print("<td>"+RS.getString("book_name")+"</td>");
out.print("<td>"+RS.getString("book_author")+"</td>");
out.print("<td>"+RS.getString("book_press")+"</td>");
out.print("<td>"+RS.getFloat("book_price")+"</td>");
out.print("<td>"+RS.getString("book_date").substring(0,10)+"</td>");
out.print("</tr>");
//注意数据类型
}
的book_id,book_name,...改为的‘b’改为大写,会快一点吧,因为你数据库里面都是大写的,你这样当然是错了!
while(RS.next())
{
out.print("<tr>");
out.print("<td>"+RS.getString("book_id")+"</td>");
out.print("<td>"+RS.getString("book_name")+"</td>");
out.print("<td>"+RS.getString("book_author")+"</td>");
out.print("<td>"+RS.getString("book_press")+"</td>");
out.print("<td>"+RS.getFloat("book_price")+"</td>");
out.print("<td>"+RS.getString("book_date").substring(0,10)+"</td>");
out.print("</tr>");
//注意数据类型
}
的book_id,book_name,...改为的‘b’改为大写,会快一点吧,因为你数据库里面都是大写的,你这样当然是错了!
#5
补充一点,我在数据库里的表项是book_id,book_name,这里的BookName等是我的临时变量,传递参数用的,我在用request.getParameter()时参数传递没有问题,也就是说showData.jsp没有错
我的同事给我的例子里,private String User为大写,这里采用大写主要考虑getBookName()方法的命名规律,(开头小写,以后每个单词都大写开头,:))
不过我会一试的,多谢
我的同事给我的例子里,private String User为大写,这里采用大写主要考虑getBookName()方法的命名规律,(开头小写,以后每个单词都大写开头,:))
不过我会一试的,多谢
#6
public class TestBean
{
private int userId;
private String userName;
public int getUserId()
{
return userId;
}
public void setUserId(int userId)
{
this.userId=userId;
}
public String getUserName()
{
return userName;
}
public void setUserName(String userName)
{
this.userName=userName;
}
}
这样才符合JavaBean属性的命名规范,叫做getter和setter方法。
{
private int userId;
private String userName;
public int getUserId()
{
return userId;
}
public void setUserId(int userId)
{
this.userId=userId;
}
public String getUserName()
{
return userName;
}
public void setUserName(String userName)
{
this.userName=userName;
}
}
这样才符合JavaBean属性的命名规范,叫做getter和setter方法。
#7
多谢各位好意,规范的问题我会注意的,但是问题解决阿,那有什么用,期待达淫中.....
#8
问题解决:
String bookId=request.getParameter("bookId");
String bookName=request.getParameter("bookName");
bookName=new String(bookName.getBytes("ISO-8859-1"),"GBK");
String bookAuthor=request.getParameter("bookAuthor");
bookAuthor=new String(bookAuthor.getBytes("ISO-8859-1"),"GBK");
String bookPress=request.getParameter("bookPress");
bookPress=new String(bookPress.getBytes("ISO-8859-1"),"GBK");
String bookPrice=request.getParameter("bookPrice");
String bookDate=request.getParameter("bookDate");
添加如上代码,主要是SQL语句用到的变量要声明,以及中文编码解决。
还是感谢各位的支持,实际上不用以下代码
<jsp:useBean id="bookdata" scope="session" class="hunan.BookData"/>
<jsp:setProperty name="bookdata" property="bookId"/>
<jsp:setProperty name="bookdata" property="bookName"/>
<jsp:setProperty name="bookdata" property="bookAuthor"/>
<jsp:setProperty name="bookdata" property="bookPress"/>
<jsp:setProperty name="bookdata" property="bookPrice"/>
<jsp:setProperty name="bookdata" property="bookDate"/>
也可以实现,这就是我说的用request的getParameter()方法。
String bookId=request.getParameter("bookId");
String bookName=request.getParameter("bookName");
bookName=new String(bookName.getBytes("ISO-8859-1"),"GBK");
String bookAuthor=request.getParameter("bookAuthor");
bookAuthor=new String(bookAuthor.getBytes("ISO-8859-1"),"GBK");
String bookPress=request.getParameter("bookPress");
bookPress=new String(bookPress.getBytes("ISO-8859-1"),"GBK");
String bookPrice=request.getParameter("bookPrice");
String bookDate=request.getParameter("bookDate");
添加如上代码,主要是SQL语句用到的变量要声明,以及中文编码解决。
还是感谢各位的支持,实际上不用以下代码
<jsp:useBean id="bookdata" scope="session" class="hunan.BookData"/>
<jsp:setProperty name="bookdata" property="bookId"/>
<jsp:setProperty name="bookdata" property="bookName"/>
<jsp:setProperty name="bookdata" property="bookAuthor"/>
<jsp:setProperty name="bookdata" property="bookPress"/>
<jsp:setProperty name="bookdata" property="bookPrice"/>
<jsp:setProperty name="bookdata" property="bookDate"/>
也可以实现,这就是我说的用request的getParameter()方法。