aspose file tools*
The moose likes Servlets and the fly likes small question for a e-store problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "small question for a e-store problem" Watch "small question for a e-store problem" New topic
Author

small question for a e-store problem

Aris Doxakis
Ranch Hand

Joined: Dec 05, 2004
Posts: 136

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
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Amarender Reddy
Ranch Hand

Joined: May 12, 2005
Posts: 54
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
Neeraj Dheer
Ranch Hand

Joined: Mar 30, 2005
Posts: 225
"<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

Joined: Dec 05, 2004
Posts: 136

how can i send the ISBN number through the <a hrf> tag ???
and then take it with a request.getparameter ???

Sarah Mahood
Greenhorn

Joined: May 20, 2005
Posts: 1
I think you are all a load of freaks. Elliotts sister smokes
 
Don't get me started about those stupid light bulbs.
 
subject: small question for a e-store problem