get a single product details
expand Bookdao Class, realize the book information method according to ISBN value
Its realization and acquisition of all goods is very similar. There is also a preparedstatment attribute that can be used to pass a parameter.
Public book GETBOOKBYISBN (String ISBN) {Connection conn = null;
PreparedStatement prestmt = null;
ResultSet bookset = null; try{//---------------1. Connect database------------------conn = dbhelper.getconnection ();//---------------2. Execute SQL statements, receive
Execute result set resultset------------------String sql = "SELECT * from book where isbn=?;";
prestmt = conn.preparestatement (sql);
Prestmt.setstring (1, ISBN);
Bookset = Prestmt.executequery (); ---------------3.
Processing execution result set resultset------------------if (Bookset.next ()) {Book book = new book ();
Book.setauthor (bookset.getstring ("author"));
Book.setimg (bookset.getstring ("img"));
Book.setintro (bookset.getstring ("Intro"));
BOOK.SETISBN (Bookset.getstring ("ISBN"));
Book.setname (bookset.getstring ("name"));
Book.setprice (Float.parsefloat) (Bookset.getstring ("price")); Book.setprice_original (Float.parsefloat (BookseT.getstring ("price_original"));
Book.setpublish_company (bookset.getstring ("Publish_company"));
Time format SimpleDateFormat DateFormat = new SimpleDateFormat ("YYYY year mm month DD Day");
Parseposition pos = new parseposition (0);
Book.setpublish_time (Dateformat.parse (bookset.getstring ("name"), POS);
return book;
}else{return null;
}}catch (Exception ex) {ex.printstacktrace ();
return null; }finally{//---------------4. Shut down resultset, Statement------------------//As necessary to ensure that resources are not occupied, you need to release resources at Fianlly, note that this can not be closed
Connection, otherwise the error//release ResultSet if (bookset!= null) {try{bookset.close ();
Bookset = null;
}catch (Exception ex) {ex.printstacktrace ();
}//Release statement object: PreparedStatement if (prestmt!= null) {try{ Prestmt.closE ();
prestmt = null;
}catch (Exception ex) {ex.printstacktrace (); }
}
}
}
Show single Item Detail page
It's not hard to see that the index.jsp and single pages are the same head and tail, so we can optimize the code with the include instructions in the 3 compiler directives (page, include, and taglib) of the JSP.
Using the include directive, you can embed an external file into the current JSP file and parse the JSP statement in the page. The syntax is as follows:
<%@ include file= "file relative path"%>
So, let's create two files: header.jsp and footer.jsp to store the header and tail code of the page separately. Then single.jsp the code as follows. At the same time, modify the index.jsp file in the same way.
header.jsp
<% String Path = Request.getcontextpath ();
String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/"; %> <! DOCTYPE html>
footer.jsp
<div class= "Footer" >
<div class= "Container-fluid" >
<div class= "Row" >
<div class= " Col-md-3 ">
</div>
<div class=" Blog-coyp col-md-6 ">
<div class=" blog text-left "> <a href= "Https://github.com/donespeak" target= "_blank" >GITHUB</a> | <a href= "Http://blog.csdn.net/donespeak" target= "_blank" >CSDN</a> | email:yangguanr@gmail.com </div><div class= "Copy text-right" >©DoneSpeak.inc</div>
</div>
</div>
</div>
</div>
<script src= "./js/jquery-2.1.4.min.js "></script>
<script src="./bootstrap-3.3.0/js/bootstrap.min.js "></script>
< Script src= "./js/script.js" ></script>
</body>
single.jsp
<%@ page language= "java" import= "java.util.*" contenttype= "text/html; Charset=utf-8 "pageencoding=" utf-8 "%> <%@ page import=" entity. Book "%> <%@ page import=" DAO. Bookdao "%> <%@ include file=" header.jsp "%> <div class=" main Newbook-all "> <div class=" con Tainer-fluid "> <div class=" Row "> <% bookdao bookdao = new book
DAO ();
Book book = BOOKDAO.GETBOOKBYISBN (Request.getparameter ("ISBN")); if (book!= null) {%> <div class= "col-md-3 col-md-offset-1 col-sm-4 col-sm-offset-1" &
Gt
<div class= "book-img" >
</div> </div> <div class= "sell col-md-5 col-sm-6" > <div class= "Booktext" >
include Directives
The above method of using include is a static include directive that embeds the contents of the specified file into the location of the instruction and compiles it. If the embedded file needs to change frequently, it is recommended that you use an operation instruction.
is an action instruction, and its <% @include%> compiler instructions are very different, it is not the contents of the file directly embedded, but run independently, the resulting output (HTML) embedded, so the inside of the Java code is not imported. In fact, a servlet is generated independently of the specified file, and <%@ include%> does not. The basic syntax format is as follows:
<jsp:include page= "{relativeurl | <%=expression%>}" flush= "true"/> <%--
or--%> <jsp
: Include page= "{Relativeurl | <%=expressi