This is my search
servlet when somebody wants to find the books of a particular author
he searches by author.this servlet reurns the data from a database
and shows them on a html page
i have a buy button for each book that is displayed
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Search extends HttpServlet
{
Connection con;
public void init()
{
Conne TheConnection=new Conne();
con=TheConnection.getConnection();
}
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String Author = request.getParameter("Author");
String Title = request.getParameter("Title");
String Section = request.getParameter("Section");
out.println("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'");
out.println("'http://www.w3.org/TR/html4/loose.dtd'>");
out.println("<head>");
out.println("<title>Search Results</title>");
out.println("</head>");
out.println("<html>");
out.println("<body>");
out.println("<Table width='140%'> <TR> <TD> <img src='/images/logo.JPG' width='217' height='117'> </TD>" +
"</TR>");
out.println("</table>");
out.println("<hr align='center' width='100%' size='7' noshade color='Red'>");
out.println("<table width='90%' height='10%' " +
"allign='center' bordercolor='red'>");
try
{
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select ISBN,Title,Author,Description,Category,Price,Url From products Where Title Like '"
+ Title + "%'" + "And Author Like '" + Author + "%'" + "And Category Like '" + Section + "%' Order By Title;");
while (rs.next())
{
String ISBN1 = rs.getString("products.ISBN");
String Author1 = rs.getString("products.Author");
String Title1 = rs.getString("products.Title");
String Description1 = rs.getString("products.Description");
String Category1 = rs.getString("products.Category");
String Price1 = rs.getString("products.Price");
String Url = rs.getString("products.Url");
out.println("<tr> <td colspan=4><h2>" + Title1 + "</h2></td></tr>" +
"<tr><td rowspan=4> <img src = 'C:/Tomcat 4.1/webapps/ROOT" + Url + "' width = '60' height = '80'> </td>" +
"<td colspan=1>" + Author1 + "</td></tr>" +
"<tr><td colspan=1>" + Description1 + "</td></tr>" +
"<tr><td colspan=1>" + Category1 + "</td></tr>" +
"<tr><td colspan=1> <h3>" + Price1 + " Euro </h3> </td></tr>" +
"<tr><td> ISBN: " + ISBN1 + "</td>" +
"<td> <a href = '/time.jsp'>" +
"<img src = 'C:/Tomcat 4.1/webapps/ROOT/images/buy.GIF' width = '15' height = '20'> </a> </td></tr>" +
"<tr><td> <hr align='center' width='100%' size='2' noshade color='Gray'> </td></tr>");
}
}
catch (SQLException e)
{
log("SQL Exception",e);
}
out.println("</table>");
out.println("</html>");
out.println("</body>");
}
}
the problem is that how can i fin out what book the person had pressed the buy button
help needed
thnx in advance
