Help: a jsp + javabean problems
Abstract: Help: A + javabean problems jsp
↑ Back
Bookstore.jsp the original code is as follows:
<% @ Page language = "java" contentType = "text / html; charset = UTF-8"
PageEncoding = "UTF-8"%>
<% Request.setCharacterEncoding ( "UTF-8");%>
<% @ Page import = "java.util .*, database .*"%>
<% @ Include file = "head.html"%>
HTML PUBLIC "- / / W3C / / DTD HTML 4.01 Transitional / / EN">
<head>
</ Head>
<body>
<table>
<% For (ListIterator iter = bookDB.getBooks (). ListIterator (); iter.hasNext ();){
BookDetails book = (BookDetails) iter.next ();
%>
<tr>
<td Bgcolor="#ffffaa">
">
<% = Book.getTitle ()%>
</ Td>
<td Bgcolor="#ffffaa" rowspan=2>
<% = Book.getPrice ()%> yuan
</ Td>
<td Bgcolor="#ffffaa" rowspan=2>
">
Add to Cart
</ Td>
</ Tr>
<tr>
<td Bgcolor="#ffffff">
Author: <% = book.getName ()%>
</ Td>
</ Tr>
<%}%>
</ Table>
</ Body>
Error pages are as follows:
HTTP Status 500 –
————————————————– ——————————
Type Exception report
Message
Description The server encountered an internal error () that prevented it from fulfilling this request.
Exception
Org.apache.jasper.JasperException: Exception in JSP: / bookstore.jsp: 15
12: </ head>
13: <body>
14: <table>
15: <% for (ListIterator iter = bookDB.getBooks (). ListIterator (); iter.hasNext ();){
16: BookDetails book = (BookDetails) iter.next ();
17:%>
18: <tr>
Stacktrace:
Org.apache.jasper.servlet.JspServletWrapper.handleJspException (JspServletWrapper.java: 504)
Org.apache.jasper.servlet.JspServletWrapper.service (JspServletWrapper.java: 375)
Org.apache.jasper.servlet.JspServlet.serviceJspFile (JspServlet.java: 314)
Org.apache.jasper.servlet.JspServlet.service (JspServlet.java: 264)
Javax.servlet.http.HttpServlet.service (HttpServlet.java: 802)
Root cause
Javax.servlet.ServletException: [Microsoft] [SQLServer 2000 Driver for JDBC] [SQLServer] Article 1: 'books' near grammatical mistakes.
Org.apache.jasper.runtime.PageContextImpl.doHandlePageException (PageContextImpl.java: 858)
Org.apache.jasper.runtime.PageContextImpl.handlePageException (PageContextImpl.java: 791)
Org.apache.jsp.bookstore_jsp._jspService (bookstore_jsp.java: 133)
Org.apache.jasper.runtime.HttpJspBase.service (HttpJspBase.java: 97)
Javax.servlet.http.HttpServlet.service (HttpServlet.java: 802)
Org.apache.jasper.servlet.JspServletWrapper.service (JspServletWrapper.java: 332)
Org.apache.jasper.servlet.JspServlet.serviceJspFile (JspServlet.java: 314)
Org.apache.jasper.servlet.JspServlet.service (JspServlet.java: 264)
Javax.servlet.http.HttpServlet.service (HttpServlet.java: 802)
Root cause
Database.BookNotFoundException: [Microsoft] [SQLServer 2000 Driver for JDBC] [SQLServer] Article 1: 'books' near grammatical mistakes.
Database.BookDBAO.getBooks (BookDBAO.java: 60)
Database.BookDB.getBooks (BookDB.java: 25)
Org.apache.jsp.bookstore_jsp._jspService (bookstore_jsp.java: 86)
Org.apache.jasper.runtime.HttpJspBase.service (HttpJspBase.java: 97)
Javax.servlet.http.HttpServlet.service (HttpServlet.java: 802)
Org.apache.jasper.servlet.JspServletWrapper.service (JspServletWrapper.java: 332)
Org.apache.jasper.servlet.JspServlet.serviceJspFile (JspServlet.java: 314)
Org.apache.jasper.servlet.JspServlet.service (JspServlet.java: 264)
Javax.servlet.http.HttpServlet.service (HttpServlet.java: 802)
Note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
A table in the database are books, jsp link database has been tested and there is no problem, I do not know the wrong page
Javax.servlet.ServletException: [Microsoft] [SQLServer 2000 Driver for JDBC] [SQLServer] Article 1: 'books' near grammatical mistakes.
What does that mean?
Members hope the guidance of experts, thank you ~!
BookDBAO of the original code is as follows:
Package database;
Import java.sql .*;
Import java.util .*;
(Public class BookDBAO
Private ArrayList books;
Connection con;
Public BookDBAO () throws Exception (
Try (
Class.forName (Constans.dbdriver). NewInstance ();
Con = DriverManager.getConnection (Constans.dburl, Constans.username, Constans.password);
) Catch (Exception ex) (
Throw new Exception ( "Couldn't open connection to database:" + ex.getMessage ());
)
)
Public void remove () (
Try (
Con.close ();
) Catch (SQLException ex) (
System.out.println (ex.getMessage ());
)
)
Public List getBooks () (throws BookNotFoundException
Books = new ArrayList ();
Try (
String selectStatement = "selcet id, name, title, price, onSale, year, descripton, inventory" + "from books";
PreparedStatement prepStmt = con.prepareStatement (selectStatement);
ResultSet rs = prepStmt.executeQuery ();
While (rs.next ()) (
BookDetails bd = new BookDetails (rs.getString (1), rs.getString (2), rs.getString (3), rs.getFloat (4), rs.getBoolean (5), rs.getInt (6), rs. getString (7), rs.getInt (8));
If (rs.getInt (8)> 0) (
Books.add (bd);
)
)
PrepStmt.close ();
) Catch (SQLException ex) (
Throw new BookNotFoundException (ex.getMessage ());
)
Collections.sort (books);
Return books;
)
Public BookDetails getBookDetails (String bookId) throws BookNotFoundException (
Try (
String selectStatement = "selcet id, name, title, price, onSale, year, description, inventory" + "from books where id =?";
PreparedStatement prepStmt = con.prepareStatement (selectStatement);
PrepStmt.setString (1, bookId);
ResultSet rs = prepStmt.executeQuery ();
If (rs.next ()) (
BookDetails bd = new BookDetails (rs.getString (1), rs.getString (2), rs.getString (3), rs.getFloat (4), rs.getBoolean (5), rs.getInt (6), rs. getString (7), rs.getInt (8));
PrepStmt.close ();
Return bd;
Else ()
PrepStmt.close ();
Throw new BookNotFoundException ( "couldn't find book:" + bookId);
)
) Catch (SQLException ex) (
System.err.println (ex.getMessage ());
Throw new BookNotFoundException ( "couldn't find book:" bookId + + "" + ex.getMessage ());
)
)
Public void buyBooks (ShoppingCart cart) throws OrderException (
Collection items = cart.getItems ();
Iterator i = items.iterator ();
Try (
Con.setAutoCommit (false);
While (i.hasNext ()) (
ShoppingCartItem sci = (ShoppingCartItem) i.next ();
BookDetails bd = (BookDetails) sci.getItem ();
String id = bd.getBookId ();
Int quantity = sci.getQuantity ();
BuyBook (id, quantity);
)
Con.commit ();
Con.setAutoCommit (true);
) Catch (Exception ex) (
Try (
Con.rollback ();
Throw new OrderException ( "transaction failed:" + ex.getMessage ());
) Catch (SQLException sqx) (
Throw new OrderException ( "rollback failed:" + sqx.getMessage ());
)
)
)
Public void buyBook (String bookId, int quantity) throws OrderException (
Try (
String selectStatement = "select id, name, title, price, onSale, year, description, nventory" + "from books where id =?";
PreparedStatement prepStmt = con.prepareStatement (selectStatement);
PrepStmt.setString (1, bookId);
ResultSet rs = prepStmt.executeQuery ();
If (rs.next ()) (
Int inventory = rs.getInt (8);
PrepStmt.close ();
If ((inventory-quantity)> = 0) (
String updateStatement = "= update books set inventory-inventory? Where id =?";
PrepStmt = con.prepareStatement (updateStatement);
PrepStmt.setInt (1, quantity);
PrepStmt.setString (2, bookId);
PrepStmt.executeUpdate ();
PrepStmt.close ();
Else ()
Throw new OrderException ( "not enough of the" bookId + + "in stock to comp; ete order.");
)
)
) Catch (Exception ex) (
Throw new OrderException ( "couldn't purchase book:" bookId + + ex.getMessage ());
)
)
)
OrderException BookNotFoundException and which is their own definition, the following types of documents:
Package database;
Public class BookNotFoundException extends Exception (
Public BookNotFoundException () (
)
Public BookNotFoundException (String msg) (
Super (msg);
)
)
OrderException similar
Sql statement a problem it is not from lack of space before, I did not carefully elusive your code, the initial guess what!
Sql print, in the implementation of this oracle, whether or not they can implement successful!
Releated Java Articles
Comments
Leave a Reply






