Combine drop down and a text field to a submit button and display "result" using JSP

Hi guys, I'm using JSP to create a web based shopping system. I've never done any JSP before, so I hope you guys can help me out.

What i have done so far is to fill the drop down list with values from a SQL database. I have created a text field and a submit button.

The thing is, when a user makes a choice from the drop down list, the user should then provide the quantity of this product in the text field, and when the choice(drop down) AND the quantity(textfield) has been entered, the user press the submit button called "add to order", and a table should then appear on the same page, providing information about the selected product(prod_code,description), the quantity, the price for the product and total cost. So, for each product the user select, a new entry should be added to the table. The user should also be able to delete selected products one by one.

When the user checks out using a submit buttion, this order should be stored in a database and the user should be redirected to another site giving a summary of the products bought. When the user then exit this page(submit button), the session will be terminated and the tables in the database should be updated.

Tables in the database:

Code for this part so far:
     if (submitValue.equals("newOrder") ) {
     <H1> Rocky Concrete </H1>
     <p><b> Catalogue: </b>
     Connection connection = null;
     Statement stat = null;
     ResultSet rs = null;
     String queryProducts = null;
     connection = DriverManager.getConnection("jdbc:odbc:rocky");
     stat = connection.createStatement();
     queryProducts = "Select prod_code, description, list_price From Products Order by prod_code";

     rs = stat.executeQuery(queryProducts);
     ResultSetMetaData rsmd = rs.getMetaData();
<select name=CAT>
     while (
          String prodCode = rs.getString("prod_code");
          String des = rs.getString("description");
          int price = rs.getInt(3);
          <option><%=prodCode%> | <%=des%> | <%=price%>

<b>Quantity: </b> <INPUT type="text" id="quantity"> <INPUT type="submit" value="Add to order">


I hope i did not scare you away from answering this question, i know there is quite a few details and it's a time consuming task, but if anyone are willing to help as soon as possible i would be extremly grateful, and i will for sure give you the best grade and maximum points for helping me out.

Kind regards,
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

what do you need help with?  The entire thing?  We can't code the entire thing for you b/c that is not what this site is about.  Its about helping and guiding.  We can tell you approaches and guide you with sample/pseudo code but you must make an effort and we can help you along the way.  Sound fair?

SchronAuthor Commented:
How can i combine the choice made in the drop down list with the number entered in the textfield and show the result?

One way you can do is ... I have explained the steps ... you need to implement the similar.

1. Create a new java class (Value Object)
public class OrderData implements

     private Long orderId;
        private Long productId;
        private String productName;
        private long quantity;
        private double price;
        private double unitPrice;

//Create all getter and setter methods for these variables.

2. While loading the product from the db to the dropdown, load the prices of each item and store in a hashtable with productId as the key and Price as the value and store this hashtable in the session object.

3. In the JSP page add one more field
<INPUT type="hidden" id="productName"> to store the selected product name.

4. In the JSP page add one more field
<INPUT type="hidden" id="action"> to store the current action.

5. Make you product option something like this
    <option value="<%=prodCode%>"><%=prodCode%> | <%=des%> | <%=price%></option

6. While submitting the jsp page populate the productName field using javascript. Call this method in onsubmit event of the form (i.e. "onsubmit = validateForm(this)")
  <SCRIPT language="javascript">
     function validateForm(formObj){
       var productNameStr = formObj.CAT.options[selectedIndex].text;
       var nameArr = productNameStr.split("|");
       formObj.productName.value = nameArr[1];
       return true;

7. On the top of the jsp page get the orderHash from session and add/update the selected product to it and put it back to session.

      String action = request.getParameter("action");
      if(action != null && action.equals("add"){
          Long productId = new Long(request.getParameter("CAT"));
          String productName = request.getParameter("quantity");
          long qty = Long.parseLong(request.getParameter("productName"));
          double price = 0;
          Hashtable priceHash = session.getAttribute("priceHash");
          if(priceHash != null){
            price = Double.parseToDouble(priceHash.get(productId));
          Hashtable orderHash = session.getAttribute("orderHash");
          OrderData ord = null;
          if(orderHash != null){
            ord = (OrderData)priceHash.get(productId);
          if(ord == null){
            ord = new OrderData();
          double prevPrice = ord.getPrice();
          ord.setPrice((qty * price) + prevPrice);


8. While displaying do the following
      <TD>Unit Price</TD>
      double totalPrice = 0;
      Hashtable orderHash = (Hashtable)session.getAttribute("orderHash");
      if(orderHash != null && orderHash.size() > 0){
        Enumeration orderEnum = orderHash.elements();
          OrderData ord = (OrderData)orderEnum.nextElement();
          totalPrice += ord.getPrice();
         <TD colspan=4>total : <%= totalPrice%></TD>


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

You can put a button called done in your JSP page which will submit the page and you can actually add the data from the hashtable(orderHash) in session to the database.
One more thing
 For quantity also
replace the following
     long prevQty = ord.getQuantity();
     ord.setQty(qty + prevQty);
Hmmm i might use some of this for my ITB262 assignment as well :p
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.