This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!

kripa ganesh

Greenhorn
+ Follow
since Nov 01, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by kripa ganesh

Thanx
I tried out what u said, but am sorry it didnt work. can someone help me with a sample code using hash table, so that i can follow the same and correct mine.
19 years ago
Hello,
Pls find below the code i used for the cart items.
The qty is entered in a previous servlet and passed to this servlet. Here if the qty is 0 then no item should be displayed. If there are more than one items then it should list all of them.
Pls Help!! AM Stuck with this code. IS there any other alternative way to do it..Pls help..
package imshoppe;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
import java.util.Properties;
import java.util.Enumeration;
import java.util.Hashtable;
import java.text.NumberFormat;
import java.lang.*;
public class ShoppingCart extends HttpServlet {
private Connection dbc;
public void init(ServletConfig config) throws ServletException {
super.init(config); dbc = null;
// connecting to database
Statement stmt = null;
ResultSet rs = null;
String host = "localhost";
String user="root";
String pass="";
String db="shop";
String con;
try {
Class.forName("org.gjt.mm.mysql.Driver");
con="jdbc:mysql://" + host + "/" + db +"?user=" + user +"&password="+pass;
Connection Conn = DriverManager.getConnection(con);
stmt = Conn.createStatement();

} catch (Exception e) {
e.printStackTrace();
}
}
public void destroy()
{
try
{ dbc.close();
}
catch (SQLException e)
{ e.printStackTrace(); }
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
Hashtable cart;
PrintWriter out;
out = response.getWriter();
response.setContentType("text/html");
HttpSession session = request.getSession(true);
String id = request.getParameter("prodid");
String command = request.getParameter("command");
String sessionId = request.getParameter("sessionId");
String uqty = request.getParameter("uqty");
String requestURI = request.getRequestURI();
cart = (Hashtable) session.getValue("cart");
if (cart == null)
{
cart = new Hashtable();
}
out.println("<h1>Shopping Cart</h1>");
out.print("Request URI: "+request.getRequestURI());
out.print("<br>");
out.print("The Product ID retrieved from previous servlet:" + id);
out.print("<br>");
out.print("The Session ID retrieved: " + sessionId);
out.print("<br>");
out.print("The Command retrieved: " + command);
out.print("<br>");
out.print("The qty ordered : " + uqty);
out.print("<br>");
if
(command.equals("add"))
{
Integer num = (Integer) cart.get(id);
if (num == null) {
num = new Integer(0);
}
session.setAttribute(id, new Integer(num.intValue()+1) );
//printCatalog(out, requestURI);
out.println("Item Added to Cart");
}
else if
(command.equals("viewcart"))
{
printCart(cart, out, requestURI);
}
else
{
out.println("Back to Shopping");
//printCatalog(out, requestURI); }
session.setAttribute("cart", cart); }
}
private void printCart(Hashtable cart, PrintWriter out, String requestURI) throws
ServletException, IOException
{
Statement stmt;
ResultSet rs=null;
double total = 0.0;
//Integer prod = rs.getInt("prodid");
out.println("<td><a href=\"" + requestURI + "?command=viewcart"+ "\">View Cart</a></td>");
Enumeration keys = cart.keys();
NumberFormat nf = NumberFormat.getCurrencyInstance();
out.println("Your cart contains:");
out.println("");
out.println("Quantity Item Price Subtotal ");
while (keys.hasMoreElements())
{
String id = (String) keys.nextElement();
Integer qty = (Integer) cart.get(id);
try {
stmt = dbc.createStatement();
stmt.execute("select * from prods where pid = " + id);
rs = stmt.getResultSet();
double subtotal = rs.getDouble("rat") * qty.intValue();
out.println("");
out.println("" + qty.toString() + "");
out.println("" + rs.getString("pnam") + "");
out.println("" + nf.format(rs.getDouble("rate")) + "");
out.println("" + nf.format(subtotal ) + "");
out.println(" ");
total += subtotal;
rs.close();
stmt.close();
}
catch (SQLException e) {
e.printStackTrace();
}
}
out.println("TOTAL:" + nf.format(total) + "");
out.println("");
out.println("Back to Shopping");
}
}
19 years ago
Have been trying to add items to the cart using servlets. Only the recent item added is displayed. How is it possible to add multiple products to the cart and once the user clicks the add to cart, the linked servlet should display the items (if already added ) alongwith the recent item added..
Any one can you pls help me with a sample code...
Thanx in advance,
kripa
19 years ago
Thanx a lot for the timely help.. have solved the problem with your suggestions.
19 years ago
Hello,
Am using Tomcat 3.2.1 and Servlets 2.1 for a small cart project. But whenever i use the post method the tomcat server it gives out an error that says Page could not be displayed because the service is not available..
Kindly help me on what i should do to get it working, is there any change i should make in the xml files to use the post method??
pls help
thanx
Kripa
19 years ago

Am working on a mysql project wherein i have to display results from
a database to a html table which should display the first row in the
first column of the table and the second row in the second column of
the table. I could not succeed by using the while rs.next(). Please
help me.
I use mysql database and use servlets to display the content in a
html table.
In the same way is it possible to get one field from a table and
display the column within a combo box. i have tried some ways but it
dosent seem to work. Some body pls help me out...
20 years ago
Hello all,
Am struck in the middle of a project. i use Mysql, tomcat3.2.1 on win 98.
Actually the requirement is that, data from a field in a mysql table needs to be read and displayed within a combo box. no idea as to what should be done..pls help.
the combo that displays the field from a table will be used to select options in a html file and the option thus selected got to be stored back into another table
eg: Product category - say..Grocery, Cosmetics
Product name - Spices, Perfume...
So if a user is going to add he/she should select from the predefined category Grocery, cosmetics etc. Then the user will enter the specific prod name into a text field...
20 years ago
Hi,
Am comparatively new to servlets and MYsql. Am using Tomcat app server on Win 98. I wrote a servlet that is supposed to connect to a Mysql database and display the records. But the servlet displays the headings given out as html tables..and then it comes out with errors as given below..The driver am using is mm.mysql.driver..
I tried setting the class path
c:\jdk1.3\lib\mmsql.jar.. it didnt work..am getting puzzled as to where the jar file should be put now.. how do i extract the driver's class file from the jar.
*****
Headings
CategoryProduct NameProduct Rate
Error: 500
Location: /examples/servlet/imshoppe.ProductsInternal Servlet Error:javax.servlet.ServletException: JDBC Driver not found.
at imshoppe.Products.doPost(Products.java:81)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
at org.apache.tomcat.core.Handler.service(Handler.java:286)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:210)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
at java.lang.Thread.run(Thread.java:484)
Root cause:
java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
at org.apache.tomcat.loader.AdaptiveClassLoader.loadClass(AdaptiveClassLoader.java:524)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:120)
at imshoppe.Products.doPost(Products.java:58)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
at org.apache.tomcat.core.Handler.service(Handler.java:286)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:210)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
at java.lang.Thread.run(Thread.java:484)
20 years ago