• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

small question for a e-store problem

 
Ranch Hand
Posts: 136
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aris,
Any time you post more than a line or two of code, you should wrap it in a set of UBB tags. There is a button on the "NewTopic/Reply" page that builds the tag for you. The tag makes your code more readable by preserving the indenting. This, in turn, makes it more likely that someone else will read it and increases the chance that someone will help you.
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Aris,

Hope you have understood what Ben was trying to say regarding the formatted

code and hope you will follow that.Coming to your query, its quite clear

that the unique ISBN will be the PK---as simple as that.

cheers
amar
 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

"<td> <a href = '/time.jsp'>"


just add the name of the book with this as a query string and you can extract it on the server side using request.getParameter("name")
 
Aris Doxakis
Ranch Hand
Posts: 136
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how can i send the ISBN number through the <a hrf> tag ???
and then take it with a request.getparameter ???

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you are all a load of freaks. Elliotts sister smokes
 
Good night. Drive safely. Here's a tiny ad for the road:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic