-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuyBooksServlet.java
64 lines (62 loc) · 2.16 KB
/
BuyBooksServlet.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package test;
import test.DBConnection;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
public class BuyBooksServlet extends GenericServlet{
public void service(ServletRequest req,ServletResponse res) throws IOException,ServletException
{
PrintWriter pw = res.getWriter();
res.setContentType("text/html");
try {
Connection con = DBConnection.getCon();
//ArrayList<Books> al = new ArrayList<Books>();
PreparedStatement ps = con.prepareStatement("Select * from book6");
ResultSet rs = ps.executeQuery();
RequestDispatcher rd = req.getRequestDispatcher("ViewBooks.html");
rd.include(req, res);
pw.println("<div class=\"tab hd brown \">Books Available In Our Store</div>");
pw.println("<div class=\"tab\"><form action=\"buys\" method=\"post\">");
pw.println("<table>\r\n" +
" <tr>\r\n" +
" <th>Books</th>\r\n" +
" <th>Code</th>\r\n" +
" <th>Name</th>\r\n" +
" <th>Author</th>\r\n" +
" <th>Price</th>\r\n" +
" <th>Avail</th>\r\n" +
" <th>Qty</th>\r\n" +
" </tr>");
int i=0;
while(rs.next())
{
String bCode = rs.getString(1);
String bName = rs.getString(2);
String bAuthor = rs.getString(3);
int bPrice = rs.getInt(4);
int bAvl = rs.getInt(5);
i=i+1;
String n = "checked"+ Integer.toString(i);
String q = "qty"+Integer.toString(i);
pw.println("<tr>\r\n" +
" <td>\r\n" +
" <input type=\"checkbox\" name="+n+" value=\"pay\">\r\n" + //Value is made equal to bcode
" </td>");
pw.println("<td>"+bCode+"</td>");
pw.println("<td>"+bName+"</td>");
pw.println("<td>"+bAuthor+"</td>");
pw.println("<td>"+bPrice+"</td>");
pw.println("<td>"+bAvl+"</td>");
pw.println("<td><input type=\"text\" name="+q+" value=\"0\" text-align=\"center\"></td></tr>");
}
pw.println("</table>\r\n" + "<input type=\"submit\" value=\" PAY NOW \">"+"<br/>"+
" </form>\r\n" +
" </div>");
//pw.println("<div class=\"tab\"><a href=\"AddBook.html\">Add More Books</a></div>");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}