?
Solved

Databasing JSP to mySQL or Access

Posted on 2003-03-15
133
Medium Priority
?
367 Views
Last Modified: 2010-04-01
I need help with putting the product name, the product description, getPrice, and getTotal into a database and then retreiving the data to another JSP/HTML ..... the code is shown below for the Shopping Cart (the page with the data that needs to transferred to the database).  I already have the driver for mySQL (connect J) and the server; I also have microsoft Access capabilities on my computer.  Either one is fine but I would prefer mySQL.  I don't have much of a background on this so I really need someone to guide me through this.   Please....

Code for ShoppingCart.jsp:
__________________________________________________________________________________________________________________
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page language="java" contentType="text/html" %>
<%@ taglib uri="dvdtaglib.tld" prefix="dvd" %>
<%@ page import="java.text.*" %>
<%@ page import="dvdshop.DVDProductBean" %>
<%@ page import="dvdshop.DVDCatalogBean" %>
<%@ page import="dvdshop.DVDCartBean" %>

 <jsp:useBean
 id="catalog"
 scope="application"
 class="dvdshop.DVDCatalogBean"
 />

 <jsp:useBean
 id="cart"
 scope="session"
 class="dvdshop.DVDCartBean"
 />

    <%
         NumberFormat numFormat = NumberFormat.getCurrencyInstance();
    %>

<%
 if (request.getParameter("id")!=null)
 {
%>
       <%-- Get the DVDProductBean from the catalog and save it in the cart --%>
       <dvd:useProperty id="product" name="catalog" property="product"
       arg='<%= request.getParameter("id") %>'
       className="dvdshop.DVDProductBean" />
      
       <jsp:setProperty name="cart" property="product" value="<%= product %>" />
<%
 }
%>

<html>
<head>
<!-- TemplateBeginEditable name="doctitle" -->
<title>WARREN'S ON-LINE DVD STORE</title>
<!-- TemplateEndEditable --><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<!-- TemplateBeginEditable name="head" --><!-- TemplateEndEditable -->
</head>
<body marginwidth="0" marginheight="0" leftmargin="0" topmargin="0" bgcolor="#FFFFFF">
<form name="form1" method="post" action="">
  <table align="center" width="100%" border="0" cellspacing="0" cellpadding="4">
    <tr valign="top" bgcolor="#cccccc">
      <td height="36" colspan="2"> <p> <font color="#000033" size="12" face="Arial, Helvetica, sans-serif">SHOPPING
          CART </font></p>
        <center>
          Title </center></td>
      <td align="center"><p> </p>
        <p> </p></td>
      <td align="center"><p> </p>
        <p> </p>
        <p>Price</p></td>
      <td align="center"><p> </p>
        <p> </p>
        <p>Action</p></td>
    </tr>
    <tr valign="top">
      <td align="center" colspan="5"><hr noshade></td>
    </tr>
    <dvd:loop name="cart" property="products" loopId="product" className="DVDProductBean">
    <tr valign="top" bgcolor="#DCDCDC">
      <td width="14%" height="108" align="center" bgcolor="#DCDCDC"> <p>

<img src="<%= product.getImage() %>">


        </p><jsp:getProperty name="product" property="name"/> </td>
      <td width="58%"><font face="Times New Roman, Times, serif"> </font>
      <jsp:getProperty name="product" property="descr"/> </td>
      <td width="1%" align="center">  </td>
      <td width="7%" align="right"><%= numFormat.format(product.getPrice()) %></td>
      <td width="20%" align="center"> <a href="RemoveFromCart.jsp?id=<%= product.getId() %>">Remove</a>
        <br> </td>
    </tr>
    </dvd:loop>
    <tr valign="middle" bgcolor="#cccccc">
      <td height="65" colspan="2" align="right"> <p> </p>
        <p>Total:</p></td>
      <td width="1%" align="center"> </td>
      <td width="7%" align="right"> <p> <br>
          <br>
          <%= numFormat.format(cart.getTotal()) %></td>
    </tr>
    <p></p>
    </tr>
  </table>
  <p><a href="CheckOut.html">Check Out</a></p>
  <p><a href="HomePage.jsp"><font color="#000000" face="Times New Roman, Times, serif">Home
    </font><font color="#000000" face="Times New Roman, Times, serif"> </font><font face="Times New Roman, Times, serif"></font></a><strong></strong>      
  </p>
  <p><a href="Catalog.jsp">Catalog</a></p>
  <p> </p>
</form>
</body>
</html>
______________________________________________________________________________________________________________

Warren
0
Comment
Question by:VWrestle97
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 72
  • 58
  • 3
133 Comments
 
LVL 92

Expert Comment

by:objects
ID: 8144637
What exactly is it you want to store in the db?
Have you designed the necessary database tables?
0
 

Author Comment

by:VWrestle97
ID: 8144682
objects,

I want to store the name of the product being bought, the product id, the price, the total price....and all the customer information that is entered in to CheckOut.jsp

I designed the tables in Access
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Expert Comment

by:objects
ID: 8144690
ok so you will be doing the database update after the CheckOut page I would suspect. What does the checkout page look like?
0
 

Author Comment

by:VWrestle97
ID: 8144702
yeah,
kinda like this
________________________________________________________
CHECK OUT FORM

The DVD's that you are buying are:




Fill out the text fields below:

First Name:

Middle Initial:

Last Name:

Street Address:

City: State:

Zip Code:

Credit Card Number: Expiration Date:

Submit


0
 
LVL 92

Expert Comment

by:objects
ID: 8144727
Yes, and the submit button on that check out page would call another page that would then save ell the entered data in the database.
How far are you with the checkout page?
0
 

Author Comment

by:VWrestle97
ID: 8144839
objects,

I want to store the name of the product being bought, the product id, the price, the total price....and all the customer information that is entered in to CheckOut.jsp

I designed the tables in Access
0
 

Author Comment

by:VWrestle97
ID: 8144858
I just need to show the products on checkout page....
other than that.. I should be done

.... and submit button goes to the Verification and invokes the database
0
 
LVL 92

Expert Comment

by:objects
ID: 8144917
The code to execute the sql insert will look something like this:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection = java.sql.DriverManager.getConnection(connectstring, user, password);
java.sql.PreparedStatement statement = connection.prepareStatement (insertsql);
statement.executeUpdate();



0
 

Author Comment

by:VWrestle97
ID: 8144929
Isn't that sql?  do I put that on the checkout.jsp?

0
 
LVL 92

Expert Comment

by:objects
ID: 8144936
> Isn't that sql?

No it's java, but you need to pass the relevant sql to perform the update.

> do I put that on the checkout.jsp?

No you put that in page that checkout.jsp calls.
0
 
LVL 92

Expert Comment

by:objects
ID: 8145171
The connectstring to use in the getConnection() call should be something like:

jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=<mdb file>

where <mdb file> is the location of the access mdb file.
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8146864
1. First, you need to create a customer bean. which stores customer information.

2. modify your DVDCartBean to include a new public method,
public void processOrder( CustomerBean customer )
in this method, you can access to information in DVDCartBean and CustomerBean, use jdbc programming to save them in database. this is a good article to learn jdbc programming: http://java.sun.com/docs/books/tutorial/jdbc/basics/

3. Creat a DVDorder.jsp, the checkout.html or checkout.jsp submit customer info to this DVDorder.jsp, this jsp should perform following tasks
store custoerm info into CustomerBean, you can use <jsp:setProperty name="customer", property="*"/>
do necessary validation
call processOrder: <% cart.processOrder( customer ); %>
if everyting is fine, display (forward) to order confim page
if error occur, display (forward) to order error page
0
 

Author Comment

by:VWrestle97
ID: 8147151
kennethxu,

A bean is still needed to make a database?

I am not really clear on what type of database this is.....SQL or Access
0
 

Author Comment

by:VWrestle97
ID: 8147206
kennethxu,

Is creating another bean really necessary....I guess is what I am really asking
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8147591
>> I am not really clear on what type of database this is.....SQL or Access  
Comment from VWrestle97  
jdbc API is database independent. that means, you program written for one database will still work if you change to another database. when you change your datebase, all you need to do is get the rigth database driver and connection url.

>> Is creating another bean really necessary....I guess is what I am really asking
It is not a must. But if you don't create another bean, you'll have to write a lot of java code in your jsp pages. According to what your current bean/jsp design, your jsp pages are mostly scriptlet free (mean you use very little java code in jsp page), so it's better idea to keep this framework. Creating a new bean is very simple, all you need to do is implement getXXX, setXXX methods in a bean classes, for example:

package dvdshop;
public class DVDCartBean implements Serializable {
   private String firstName;
   private String lastName;
   // ... other properties

   public String getFirstName() { return firstName; }
   pulbic void setFirstName( String firstName ) { this.firstName = firstName; }

   public String getLastName() { return lastName; }
   pulbic void setLastName( String lastName ) { this.lastName = lastName; }

   // getters and setters for other properties
}
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8147593
sorry, it should be
public class DVDCustomerBean implements Serializable {
0
 
LVL 92

Expert Comment

by:objects
ID: 8147804
> Is creating another bean really necessary

Not really, you can just pass the customer information directly to the method that processes the order.
0
 
LVL 92

Expert Comment

by:objects
ID: 8148124
This'll need some mods to match your db schema but should give you the basic structure of what is required, let me know any questions you have:

<%@ page language="java" contentType="text/html" %>
<%@ taglib uri="dvdtaglib.tld" prefix="dvd" %>
<%@ page import="dvdshop.DVDProductBean" %>
<%@ page import="dvdshop.DVDCartBean" %>

<%
// Get a database connection

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=c:\dvdshopdb.mdb", user, password);


%>


 <jsp:useBean
 id="cart"
 scope="session"
 class="dvdshop.DVDCartBean"
 />

 <dvd:loop name="cart" property="products" loopId="product" className="DVDProductBean">

<%
   // Add product to db

     java.sql.PreparedStatement cust = connection.prepareStatement ("insert into orders (name, address, creditcard, productid) values (?, ?, ?, ?)");
     cust.setString(1, request.getParameter("Name"));
     cust.setString(2, request.getParameter("Address"));
     cust.setString(3, request.getParameter("CreditCard"));
     cust.setString(4, product.getId());
     cust.executeUpdate();
   
    cust.close();
%>
 </dvd:loop>

<%
   connection.close();
%>

 <%-- Redirect back to the catalog page --%>
 <dvd:redirect page="Catalog.jsp" />
0
 
LVL 92

Expert Comment

by:objects
ID: 8148126
you'll probably also want to empty the shopping cart once the order has been processed.
0
 

Author Comment

by:VWrestle97
ID: 8149623
objects,


what part of the code would I need to change...
 is DBQ uri absolute..In my case it's D:\....
 do I need to change the user and password... how do I    
     use it with the database or when do I use it?
 Do I call this file something like DVDorder.jsp

If I call it DVDorder.jsp how does does it get invoked/called by my current project....Do I call it from another jsp so that it gets invoked.

And does labels name, address, creditcard, productid need to be consistant with the labels of my database and in order?

 
0
 
LVL 92

Expert Comment

by:objects
ID: 8149684
> is DBQ uri absolute..In my case it's D:\....

yes

> do I need to change the user and password... how do I    
> use it with the database or when do I use it?

depends on the permissions you setup on the db.

> Do I call this file something like DVDorder.jsp

As good as any :)

> If I call it DVDorder.jsp how does does it get
> invoked/called by my current project....Do I call it
> from another jsp so that it gets invoked.

Yes you should invoke it when the form on Checkout.jsp is sumbitted.

> And does labels name, address, creditcard, productid
> need to be consistant with the labels of my database and
> in order?

yes (except order is not important).
The exact details will depend onm the definition of your db.
0
 

Author Comment

by:VWrestle97
ID: 8149686
kennethxu,

>include a new public method,
>public void processOrder( CustomerBean customer )
>in this method, you can access to information in >DVDCartBean and CustomerBean
     
 can you be more specific about this method
 
>Creat a DVDorder.jsp, the checkout.html or checkout.jsp

 can you be more specific about this jsp
0
 

Author Comment

by:VWrestle97
ID: 8149709
objects,

How do I invoke DVDorder.jsp in the Checkout.jsp?

what happens if a label in the jsp is not matched with a column in the database...does it get ignored or is a new column created?

0
 

Author Comment

by:VWrestle97
ID: 8149717
objects,

How do I invoke DVDorder.jsp in the Checkout.jsp?

what happens if a label in the jsp is not matched with a column in the database...does it get ignored or is a new column created?

0
 

Author Comment

by:VWrestle97
ID: 8149725
objects,

>>do I need to change the user and password...how do I    
>>use it with the database or when do I use it?

>depends on the permissions you setup on the db.

 what happens if I was not prompted with that option, should that be a concern?
0
 

Author Comment

by:VWrestle97
ID: 8149726
objects,

>>do I need to change the user and password...how do I    
>>use it with the database or when do I use it?

>depends on the permissions you setup on the db.

 what happens if I was not prompted with that option, should that be a concern?
0
 
LVL 92

Expert Comment

by:objects
ID: 8149733
> How do I invoke DVDorder.jsp in the Checkout.jsp?

<form name="checkout" method="post" action="PostOrder.jsp">

<!-- Insert your customer details for in here -->

<!-- button to submit form -->

<input type="submit">

</form>

> what happens if a label in the jsp is not matched with a column in the database

The insert will fail and you will get an error.

0
 
LVL 92

Expert Comment

by:objects
ID: 8149744
> should that be a concern?

Depends on the level of security you require for your data.
Really just an issue if others are access the computer who you don't want to be accessing your db.
0
 
LVL 92

Expert Comment

by:objects
ID: 8149761
> can you be more specific about this method

WOuld basically just include the Java code included in the jsp page above to insert record in database. Just depends on whether you want to put the code in a seperate Java class,  or embed it in the jsp.
0
 

Author Comment

by:VWrestle97
ID: 8149782
objects,

<form name="checkout" method="post" action="PostOrder.jsp">

  why is it PostOrder.jsp..what about the DVDOrder.jsp?
0
 
LVL 92

Expert Comment

by:objects
ID: 8149812
Sorry I changed names on you.
You can call it whatever you like :-)
0
 

Author Comment

by:VWrestle97
ID: 8149829
objects,

why am I getting this error:

Error: 500
Location: /jsp/PostOrder.jsp
Internal Servlet Error:

org.apache.jasper.JasperException: Unable to compile class for JSPD:\ProgrammingLanguagefiles\Borland\TogetherControl6\myprojects\project\work\localhost_8080\_0002fjsp_0002fPostOrder_0002ejspPostOrder_jsp_0.java:78: Invalid escape character.
                java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=D:\ProgrammingLanguagefiles\Borland\TogetherControl6\myDatabases\dvdshopdb.mdb", user, password);
                                                                                                                                                ^
D:\ProgrammingLanguagefiles\Borland\TogetherControl6\myprojects\project\work\localhost_8080\_0002fjsp_0002fPostOrder_0002ejspPostOrder_jsp_0.java:78: Invalid escape character.
                java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=D:\ProgrammingLanguagefiles\Borland\TogetherControl6\myDatabases\dvdshopdb.mdb", user, password);
                                                                                                                                                                         ^
D:\ProgrammingLanguagefiles\Borland\TogetherControl6\myprojects\project\work\localhost_8080\_0002fjsp_0002fPostOrder_0002ejspPostOrder_jsp_0.java:78: Invalid escape character.
                java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=D:\ProgrammingLanguagefiles\Borland\TogetherControl6\myDatabases\dvdshopdb.mdb", user, password);
                                                                                                                                                                                 ^
D:\ProgrammingLanguagefiles\Borland\TogetherControl6\myprojects\project\work\localhost_8080\_0002fjsp_0002fPostOrder_0002ejspPostOrder_jsp_0.java:78: Invalid escape character.
                java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=D:\ProgrammingLanguagefiles\Borland\TogetherControl6\myDatabases\dvdshopdb.mdb", user, password);
                                                                                                                                                                                                  ^
D:\ProgrammingLanguagefiles\Borland\TogetherControl6\myprojects\project\work\localhost_8080\_0002fjsp_0002fPostOrder_0002ejspPostOrder_jsp_0.java:78: Invalid escape character.
                java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=D:\ProgrammingLanguagefiles\Borland\TogetherControl6\myDatabases\dvdshopdb.mdb", user, password);
                                                                                                                                                                                                              ^
5 errors


0
 

Author Comment

by:VWrestle97
ID: 8149850
objects,

is it okay if I have more columns in my database than I am requesting or accessing from my jsp?
0
 
LVL 92

Expert Comment

by:objects
ID: 8149872
Try using \\ instead of \:

java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=D:\\ProgrammingLanguagefiles\\Borland\\TogetherControl6\\myDatabases\\dvdshopdb.mdb", user, password);

> is it okay if I have more columns in my database than I am requesting or accessing from my jsp?

yes

0
 

Author Comment

by:VWrestle97
ID: 8149920
objects,

is my checkout.jsp supposed to look something like this:
__________________________________________________________
<form name="checkout" method="post" action="PostOrder.jsp">

<!-- Insert your customer details for in here -->

<p>First Name:
    <input type="text" name="textfield3">
     
</p>
<p>Middle Initial:
  <input type="text" name="textfield">
</p>
<p>Last Name:
  <input type="text" name="textfield2">
</p>
<p>Street Address:
  <input type="text" name="textfield4">
</p>
<p>City:
  <input type="text" name="textfield5">
State:
<input type="text" name="textfield6">
</p>
<p>Zip Code:
  <input type="text" name="textfield7">
</p>
  <p>Credit Card Number:
    <input type="text" name="textfield8">
    Expiration Date:
    <input type="text" name="textfield9">
  </p>
  <p><a href="Catalog.jsp">Catalog</a> </p>

  <p> <a href="Verification.jsp">Submit</a></p>
  <!-- button to submit form -->

<input type="submit">

</form>

  <p>&nbsp;</p>
</form>
0
 

Author Comment

by:VWrestle97
ID: 8149943
objects,

now I am getting this error:
______________________________________________________
Error: 500
Location: /jsp/PostOrder.jsp
Internal Servlet Error:

org.apache.jasper.JasperException: Unable to compile class for JSPD:\ProgrammingLanguagefiles\Borland\TogetherControl6\myprojects\project\work\localhost_8080\_0002fjsp_0002fPostOrder_0002ejspPostOrder_jsp_0.java:79: Undefined variable: user
                java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=D:\\ProgrammingLanguagefiles\\Borland\\TogetherControl6\\myDatabases\\dvdshopdb.mdb", user, password);
                                                                                                                                                                                                                                    ^
D:\ProgrammingLanguagefiles\Borland\TogetherControl6\myprojects\project\work\localhost_8080\_0002fjsp_0002fPostOrder_0002ejspPostOrder_jsp_0.java:79: Undefined variable: password
                java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=D:\\ProgrammingLanguagefiles\\Borland\\TogetherControl6\\myDatabases\\dvdshopdb.mdb", user, password);
                                                                                                                                                                                                                                          ^
2 errors


0
 
LVL 92

Expert Comment

by:objects
ID: 8149958
> is my checkout.jsp supposed to look something like this

Basically yes, although I'm unclear what Verification.jsp is inteneded for?

> now I am getting this error:


That is because you don't have a variable name user defined. As you aren't using a user/password then just remove them:

java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=D:\\ProgrammingLanguagefiles\\Borland\\TogetherControl6\\myDatabases\\dvdshopdb.mdb");



0
 

Author Comment

by:VWrestle97
ID: 8150020
objects,

now I am getting this error:
______________________________________________________
Error: 500
Location: /jsp/PostOrder.jsp
Internal Servlet Error:

javax.servlet.ServletException: [Microsoft][ODBC Microsoft Access Driver] Could not find output table 'orders'.

0
 

Author Comment

by:VWrestle97
ID: 8150041
objects,
________________________________________________________
<p>First Name:
   <input type="text" name="textfield3">
</p>
<p>Middle Initial:
 <input type="text" name="textfield">
</p>
<p>Last Name:
 <input type="text" name="textfield2">
________________________________________________________
I don't need to change any of this code to comply with this other code...
_______________________________________________________

 java.sql.PreparedStatement cust = connection.prepareStatement ("insert into orders (name, address, creditcard, productid) values (?, ?, ?, ?)");
    cust.setString(1, request.getParameter("Name"));
    cust.setString(2, request.getParameter("Address"));
    cust.setString(3, request.getParameter("CreditCard"));
    cust.setString(4, product.getId());
    cust.executeUpdate();
0
 

Author Comment

by:VWrestle97
ID: 8150059
objects,

Verification.jsp just regenerates a page for the customer just to reveiw what is being bought and their personal information that they've entered.

so if you know how to access certain variables from the table to display them on Verification.jsp

but if that is too complicated then I could just drop it
0
 
LVL 92

Expert Comment

by:objects
ID: 8150072
> I don't need to change any of this code to comply with this other code...

Yes you will need to change it:
- you will need to match the input field names to the request parameters names.
- you will need to modify the sql statement to your database definition.

if you can post your db def I can help you with this.

> but if that is too complicated then I could just drop it

Up to you really. We can leave it out for now if you like, and can add it at a later date if required.

0
 

Author Comment

by:VWrestle97
ID: 8150897
How do I also include the products into the database; the products being bought by the customer?
0
 

Author Comment

by:VWrestle97
ID: 8151042
So far I have the following codes.....
Although I am not getting any generated errors, the code does not clear the shopping cart, and the database doesn't seem like it is connecting to my application cause the fields are not being saved in the database when I execute the submit button
_________________________________________________________
CheckOut.jsp:

<jsp:useBean
 id="cart"
 scope="session"
 class="dvdshop.DVDCartBean"
 />

<form name="checkout" method="post" action="PostOrder.jsp">

<!-- Insert your customer details for in here -->

<p>First Name:
    <input type="text" name="fname">

</p>
<p>Middle Initial:
  <input type="text" name="mname">
</p>
<p>Last Name:
  <input type="text" name="lname">
</p>
<p>Street Address:
  <input type="text" name="address">
</p>
<p>City:
  <input type="text" name="city">
State:
<input type="text" name="state">
</p>
<p>Zip Code:
  <input type="text" name="zip">
</p>
  <p>Credit Card Number:
    <input type="text" name="creditcard">
    Expiration Date:
    <input type="text" name="expiry">
  </p>

  <p><a href="Catalog.jsp">Catalog</a> </p>

  <p> <a href="Verification.jsp">Submit</a></p>
  <!-- button to submit form -->

<input type="submit">

</form>

  <p>&nbsp;</p>
</form>
<font color="#000000" size="4" face="Times New Roman, Times, serif"></font><font face="First Name"></font>

</body>
</html>
______________________________________________________
Catalog.jsp:
<%@ page language="java" contentType="text/html" %>
<%@ taglib uri="dvdtaglib.tld" prefix="dvd" %>
<%@ page import="dvdshop.DVDProductBean" %>
<%@ page import="dvdshop.DVDCartBean" %>

<%
// Get a database connection

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=D:\\ProgrammingLanguagefiles\\Borland\\TogetherControl6\\myDatabases\\dvdshopdb.mdb");


%>


<jsp:useBean
id="cart"
scope="session"
class="dvdshop.DVDCartBean"
/>

<dvd:loop name="cart" property="products" loopId="product" className="DVDProductBean">

<%
  // Add product to db
    java.sql.PreparedStatement cust = connection.prepareStatement ("insert into Customers (name, address, creditcard, productid) values (?, ?, ?, ?)");
    cust.setString(1, request.getParameter("fname")+" "+request.getParameter("mname")+" "+request.getParameter("lname"));
    cust.setString(2, request.getParameter("address"));
    cust.setString(3, request.getParameter("creditcard"));
    cust.setString(4, product.getId());

   
    cust.executeUpdate();
 
   cust.close();
%>
</dvd:loop>

<%
  connection.close();
  cart.clear();
%>

<%-- Redirect back to the catalog page --%>
<dvd:redirect page="Catalog.jsp" />
________________________________________________________
DVDCartBean.java:
package dvdshop;

import java.io.*;
import java.util.*;

/**
* This class represents a shopping cart. It holds a list of products.
* @persistent
*
*/
public class DVDCartBean implements Serializable {
   private Vector cart = new Vector();

   /**
    * Adds a product to the cart, if it's not already there.
    *
    * @param product the DVDProductBean
    */
   public void setProduct(DVDProductBean product) {
       if (product != null && cart.indexOf(product) == -1) {
           cart.addElement(product);
       }
   }

   /**
    * Returns the product list.
    *
    * @return an Enumeration of DVDProductBeans
    */
   public Enumeration getProducts() {
       return cart.elements();
   }

   /**
    * Returns the total price for all products in the cart
    *
    * @return the total price
    */
   public float getTotal() {
       float total = 0;
       Enumeration prods = getProducts();
       while (prods.hasMoreElements()) {
           DVDProductBean product = (DVDProductBean) prods.nextElement();
           float price = product.getPrice();
           total += price;
       }
       return total;
   }
   
   /**
    * Returns true if the cart is empty
    *
    * @return true if the cart is empty
    */
   public boolean isEmpty() {
       return cart.size() == 0;
   }

 public void setRemove(DVDProductBean product) {
       cart.remove(product);
  }


 public void clear()
   {
      cart.removeAllElements();
   }
}
______________________________________________________


0
 
LVL 92

Expert Comment

by:objects
ID: 8154995
> How do I also include the products into the database;
> the products being bought by the customer?

The above code already includes the product id's from the order in the database.


0
 
LVL 92

Expert Comment

by:objects
ID: 8155271
It's working ok here, are you clicking the "Submit" button on the checkout page?
0
 
LVL 92

Expert Comment

by:objects
ID: 8155402
The Submit link (to Verification.jsp) is not required, you can remove it.

<p> <a href="Verification.jsp">Submit</a></p>
0
 
LVL 92

Expert Comment

by:objects
ID: 8155541
The following includes more of your fields in the db:

    java.sql.PreparedStatement cust = connection.prepareStatement ("insert into Customers (name, address, creditcard, [Exp date], city, country, productid, [Total Price]) values (?, ?, ?, ?, ?, ?, ?, ?)");
    cust.setString(1, request.getParameter("fname")+" "+request.getParameter("mname")+" "+request.getParameter("lname"));
    cust.setString(2, request.getParameter("address"));
    cust.setString(3, request.getParameter("creditcard"));
    cust.setString(4, request.getParameter("expiry"));
    cust.setString(5, request.getParameter("city"));
    cust.setString(6, request.getParameter("country"));
    cust.setString(7, product.getId());
    cust.setString(8, ""+product.getPrice());
    cust.executeUpdate();
0
 

Author Comment

by:VWrestle97
ID: 8157320
objects,

how can you link to another page "Verification.jsp" displaying the contents of the cutomer's query from the database when pressing on the Submit Query button?

did the
 public void clear()
  {
     cart.removeAllElements();
  }
work for you too?
0
 
LVL 92

Expert Comment

by:objects
ID: 8157347
If you want to display a verification page then you need to instead call PostOrder.jsp from the verification page, and not from CheckOut.

ie.

CheckOut.jsp -> Verification.jsp -> PostOrder.jsp.

> displaying the contents of the cutomer's query from the database

If the purpose of the Verification page is to confirm the details entered then it would not display the details from the database, it would just display what the user entered.

yes clear worked for me.
0
 

Author Comment

by:VWrestle97
ID: 8157807
Ojects,

from looking at the long code I posted about 7 comments above, do you see any reason why my clear method wouldn't work?
0
 
LVL 92

Expert Comment

by:objects
ID: 8157894
The only thing I can think of is that you aren't actually calling the page, especially considering you say that nothing is getting added to database.
0
 
LVL 92

Expert Comment

by:objects
ID: 8157898
CheckOut.jsp:

<jsp:useBean
id="cart"
scope="session"
class="dvdshop.DVDCartBean"
/>

<form name="checkout" method="post" action="PostOrder.jsp">

<!-- Insert your customer details for in here -->

<p>First Name:
   <input type="text" name="fname">

</p>
<p>Middle Initial:
 <input type="text" name="mname">
</p>
<p>Last Name:
 <input type="text" name="lname">
</p>
<p>Street Address:
 <input type="text" name="address">
</p>
<p>City:
 <input type="text" name="city">
State:
<input type="text" name="state">
</p>
<p>Zip Code:
 <input type="text" name="zip">
</p>
 <p>Credit Card Number:
   <input type="text" name="creditcard">
   Expiration Date:
   <input type="text" name="expiry">
 </p>

 <p><a href="Catalog.jsp">Catalog</a> </p>

<input type="submit">

</form>

 <p>&nbsp;</p>
</form>
<font color="#000000" size="4" face="Times New Roman, Times, serif"></font><font face="First Name"></font>

</body>
</html>
0
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 8157905
PostOrder.jsp:

<%@ page language="java" contentType="text/html" %>
<%@ taglib uri="dvdtaglib.tld" prefix="dvd" %>
<%@ page import="dvdshop.DVDProductBean" %>
<%@ page import="dvdshop.DVDCartBean" %>
<%@ page import="java.sql.*" %>

<%
// Get a database connection

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=D:\\ProgrammingLanguagefiles\\Borland\\TogetherControl6\\myDatabases\\dvdshopdb.mdb");


%>


<jsp:useBean
id="cart"
scope="session"
class="dvdshop.DVDCartBean"
/>

<dvd:loop name="cart" property="products" loopId="product" className="DVDProductBean">

<%
  // Add product to db


    java.sql.PreparedStatement cust = connection.prepareStatement ("insert into Customers (name, address, creditcard, [Exp date], city, country, productid, [Total Price]) values (?, ?, ?, ?, ?, ?, ?, ?)");
    cust.setString(1, request.getParameter("fname")+" "+request.getParameter("mname")+" "+request.getParameter("lname"));
    cust.setString(2, request.getParameter("address"));
    cust.setString(3, request.getParameter("creditcard"));
    cust.setString(4, request.getParameter("expiry"));
    cust.setString(5, request.getParameter("city"));
    cust.setString(6, request.getParameter("country"));
    cust.setString(7, product.getId());
    cust.setString(8, ""+product.getPrice());
    cust.executeUpdate();
 
   cust.close();
%>
</dvd:loop>

<%
  connection.close();
  cart.clear();
%>

<%-- Redirect back to the catalog page --%>
<dvd:redirect page="Catalog.jsp" />
0
 

Author Comment

by:VWrestle97
ID: 8164215
I am having a problem with accessing the database?
0
 
LVL 92

Expert Comment

by:objects
ID: 8164635
> I am having a problem with accessing the database?

What is the problem?

It's working fine here using the two pages I posted above.
0
 

Author Comment

by:VWrestle97
ID: 8164807
I think there is a problem with the software that I am using... I think that it requires the project to be linked to the driver....  do you know what the driver is for Access... if their is no driver, I may have to do the database in mySQL
0
 
LVL 92

Expert Comment

by:objects
ID: 8164848
it simply access the database using odbc.
if you couldn't connect then u would be getting an error (are you?).
0
 

Author Comment

by:VWrestle97
ID: 8164858
no error at all
0
 

Author Comment

by:VWrestle97
ID: 8164862
the only other problem that I am getting is that the cart does not clear
0
 

Author Comment

by:VWrestle97
ID: 8164869
The software that I am using is Together Control Center 6.0 and I may have to import the driver's deatabase using the Together's database schema...
but it requires knowing the drivers location
0
 

Author Comment

by:VWrestle97
ID: 8164875
when I tried the database schema's
"test connection" button....It displayed "failed to connect"
0
 
LVL 92

Expert Comment

by:objects
ID: 8164895
The above code (unless you changed it) access the mdb file directly and does not use a DSN.
If you are not getting an error, and the cart is not clearing I strongly suspect the PostOrder.jsp page is not getting called.

Try the two pages I posted above and let me know the results. Perhaps take out the redirect at the bottom PostOPrder.jsp so it doesn't jump back to catalog.

0
 

Author Comment

by:VWrestle97
ID: 8165000
I have and I get the same results... but I'll try again
0
 
LVL 92

Expert Comment

by:objects
ID: 8165081
Try taking out the redirect.
0
 

Author Comment

by:VWrestle97
ID: 8165141
taking out redirect has no effect
0
 

Author Comment

by:VWrestle97
ID: 8165146
do I need a driver for Access?
0
 
LVL 92

Expert Comment

by:objects
ID: 8165160
Not for Access specifically, the above code uses the driver for the odbc-jdbc bridge.
What happened when you removed the redirect from the bottom of PostOrder.jsp?
0
 
LVL 92

Expert Comment

by:objects
ID: 8165187
> taking out redirect has no effect

So are you saying you end up with a blank page after hitting the submit button?
0
 

Author Comment

by:VWrestle97
ID: 8165199
I return to CheckOut.jsp
..but with the customer information fields cleared ... only leaving the labels for the fields
0
 

Author Comment

by:VWrestle97
ID: 8165202
..only leaving the lavels for the fields and the product jsp information... It just clears out all the fields that are entered in by the customer
0
 
LVL 92

Expert Comment

by:objects
ID: 8165222
> I return to CheckOut.jsp

How can that be??
Definitely sounds like PostOrder.jsp is not getting called.

Send me your current jsp files and I'll see what the problem is.
0
 

Author Comment

by:VWrestle97
ID: 8165243
PostOrder.jsp:
<%@ page language="java" contentType="text/html" %>
<%@ taglib uri="dvdtaglib.tld" prefix="dvd" %>
<%@ page import="dvdshop.DVDProductBean" %>
<%@ page import="dvdshop.DVDCartBean" %>
<%@ page import="java.sql.*" %>

<%
// Get a database connection

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=D:\\ProgrammingLanguagefiles\\Borland\\TogetherControl6\\myDatabases\\dvdshopdb.mdb");


%>


<jsp:useBean
id="cart"
scope="session"
class="dvdshop.DVDCartBean"
/>

<dvd:loop name="cart" property="products" loopId="product" className="DVDProductBean">

<%
 // Add product to db


   java.sql.PreparedStatement cust = connection.prepareStatement ("insert into Customers (name, address, creditcard, [Exp date], city, country, productid, [Total Price]) values (?, ?, ?, ?, ?, ?, ?, ?)");
   cust.setString(1, request.getParameter("fname")+" "+request.getParameter("mname")+" "+request.getParameter("lname"));
   cust.setString(2, request.getParameter("address"));
   cust.setString(3, request.getParameter("creditcard"));
   cust.setString(4, request.getParameter("expiry"));
   cust.setString(5, request.getParameter("city"));
   cust.setString(6, request.getParameter("country"));
   cust.setString(7, product.getId());
   cust.setString(8, ""+product.getPrice());
   cust.executeUpdate();
 
  cust.close();
%>
</dvd:loop>

<%
 connection.close();
 cart.clear();
%>

<%-- Redirect back to the catalog page --%>
<dvd:redirect page="Catalog.jsp" />

--------------------------------------------------------
CheckOut.jsp:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page language="java" contentType="text/html" %>
<%@ taglib uri="dvdtaglib.tld" prefix="dvd" %>
<%@ page import="java.text.*" %>
<%@ page import="dvdshop.DVDProductBean" %>

<jsp:useBean
id="cart"
scope="session"
class="dvdshop.DVDCartBean"
/>

    <%
         NumberFormat numFormat = NumberFormat.getCurrencyInstance();
    %>

<html>
<head>
<title>WARREN'S ON-LINE DVD STORE</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="form1" method="post" action="">
  <p> <strong><font color="#000033" size="12" face="Arial, Helvetica, sans-serif">CHECK
    OUT FORM</font></strong></p>

 <font color="#000033" size="4" face="Arial, Helvetica, sans-serif">DVD's you are purchasing:</font>
    <dvd:loop name="cart" property="products" loopId="product" className="DVDProductBean">
  <p><font color="#663399" size="3"><strong><font color="#000000">Product Name</font>:</strong></font>
    <font color="#663399">
    <jsp:getProperty name="product" property="name"/>
    <strong><font color="#000000" size="3">Product Price</font><font size="3">:</font></strong>
    <%= numFormat.format(product.getPrice()) %></font></p>
</dvd:loop>
  <p><font color="#669966"><strong><font color="#000000" size="3">Total Price<font color="#666666">:</font></font></strong>
    <font color="#666666"><%= numFormat.format(cart.getTotal()) %></font></font></p>

  <p><font color="#000033" size="4" face="Arial, Helvetica, sans-serif">Fill out
    the text fields below:</font></p>
  <p>&nbsp;</p>
 




<form name="checkout" method="post" action="PostOrder.jsp">

<!-- Insert your customer details for in here -->

<p>First Name:
  <input type="text" name="fname">

</p>
<p>Middle Initial:
<input type="text" name="mname">
</p>
<p>Last Name:
<input type="text" name="lname">
</p>
<p>Street Address:
<input type="text" name="address">
</p>
<p>City:
<input type="text" name="city">
State:
<input type="text" name="state">
</p>
<p>Zip Code:
<input type="text" name="zip">
</p>
<p>Credit Card Number:
  <input type="text" name="creditcard">
  Expiration Date:
  <input type="text" name="expiry">
</p>

<p><a href="Catalog.jsp">Catalog</a> </p>

<input type="submit">

</form>

<p>&nbsp;</p>
</form>
<font color="#000000" size="4" face="Times New Roman, Times, serif"></font><font face="First Name"></font>

</body>
</html>
0
 
LVL 92

Expert Comment

by:objects
ID: 8165275
get rid of the following line from CheckOut.jsp:

<form name="form1" method="post" action="">

It is causing PostOrder.jsp to not be called, and instead the page is just reloading itself.


0
 

Author Comment

by:VWrestle97
ID: 8165360
I understand now why it was wrong...
but it now works..

I noticed that a new transaction ID was created for each product that was bought... How can I make it so that it instead would list all the products bought for one
transaction ID
0
 

Author Comment

by:VWrestle97
ID: 8165364
and what if I wanted to make a field not required to be entered in by the user
0
 
LVL 92

Expert Comment

by:objects
ID: 8165452
> How can I make it so that it instead would list all the
> products bought for one transaction ID

You'll need to change your database design and have one table for storing transactions, and another table for storing the products for a transaction.

Transaction table
-----------------
tansactionid
name
address
etc

Order table
-----------------
order id
transactionid
product id
price
etc



0
 

Author Comment

by:VWrestle97
ID: 8165580
how would that change the code
0
 

Author Comment

by:VWrestle97
ID: 8165598
...if you were to stay consistant with the way you set up the table above
0
 
LVL 92

Expert Comment

by:objects
ID: 8169570
You would first insert one record into the transaction table.
And then insert multiple records (one for each product ordered) into the order table including the transaction id of the inserted transaction record as a foreign key.
0
 

Author Comment

by:VWrestle97
ID: 8171757
>each product ordered) into the order table
>>including the transaction id of the inserted >>transaction record as a foreign key.


how do you insert the transaction record as a foreign key?
0
 
LVL 92

Expert Comment

by:objects
ID: 8177882
you need to insert the transactionid of the record entered into transaction table as the transactionid of each record added to the order table.
0
 

Author Comment

by:VWrestle97
ID: 8179036
how do you transfer the transaction id like that?

I don't know how to output or transfer database information....

can you be more specific

thanks
0
 

Author Comment

by:VWrestle97
ID: 8179037
how do you transfer the transaction id like that?

I don't know how to output or transfer database information....

can you be more specific

thanks
0
 

Author Comment

by:VWrestle97
ID: 8179038
how do you transfer the transaction id like that?

I don't know how to output or transfer database information....

can you be more specific

thanks
0
 
LVL 92

Expert Comment

by:objects
ID: 8179069
You don't need to output or transfer information, you just need to include the transactionid in the updates to both tables:

insert into Transactions (transactionid, name, address, creditcard, [Exp date], city, country) ...
for each product
   insert into Orders (transactionid, productid, [Total Price]) ...

This way for every product ordered you have the id of the associated transaction record.

0
 

Author Comment

by:VWrestle97
ID: 8179094
I know what you are saying, but can you show me by code because I don't know how to insert the transactionid from "Transactions database" into the "Orders database"
0
 

Author Comment

by:VWrestle97
ID: 8179116
can I create 2 databases in one jsp or should I split them up... but then that would be more complicated though huh?
0
 
LVL 92

Expert Comment

by:objects
ID: 8179123
You not really insert the value from one table into another. You are simply inserting the same value into both tables. A timestamp is probably a good candidate to use as an id.

String id = Long.toString(new Date().getTime());

0
 
LVL 92

Expert Comment

by:objects
ID: 8179128
You're not creating two databases, you are inserting records into two tables in one databases. (Perhaps just a matter of semantics). And yes you can do it in one jsp, in fact that is what you should be doing.
0
 

Author Comment

by:VWrestle97
ID: 8179214
where do I put the time stamp?

and if I just insert the same value into both tables.. in the orders table, woun't the transaction id still be incremented before... that is unless it is only entered in once in to the tabe, but then I wouldnt need 2 tables..
0
 

Author Comment

by:VWrestle97
ID: 8179234
wouldn't time stamp be more like um..
date or time ordered?
0
 
LVL 92

Expert Comment

by:objects
ID: 8179237
> where do I put the time stamp?

Use the timestamp as the transaction id value

> won't the transaction id still be incremented

why would it be incremented?
0
 
LVL 92

Expert Comment

by:objects
ID: 8179241
The reason for using a timestamp as the id is that it will be unique. You could use any unique value.
0
 

Author Comment

by:VWrestle97
ID: 8179281
Error: 500
Location: /jsp/PostOrder.jsp
Internal Servlet Error:

org.apache.jasper.JasperException: Unable to compile class for JSPD:\ProgrammingLanguagefiles\Borland\TogetherControl6\myprojects\project\work\localhost_8080\_0002fjsp_0002fPostOrder_0002ejspPostOrder_jsp_0.java:125: No constructor matching Date() found in class java.sql.Date.
                   cust.setString(7, Long.toString(new Date().getTime()));
                                                   ^

0
 
LVL 92

Expert Comment

by:objects
ID: 8179295
Use java.util.Date:

cust.setString(7, Long.toString(new java.util.Date().getTime()));
0
 

Author Comment

by:VWrestle97
ID: 8179333
Error: 500
Location: /jsp/PostOrder.jsp
Internal Servlet Error:

org.apache.jasper.JasperException: Unable to compile class for JSPD:\ProgrammingLanguagefiles\Borland\TogetherControl6\myprojects\project\work\localhost_8080\_0002fjsp_0002fPostOrder_0002ejspPostOrder_jsp_0.java:125: Incompatible type for method. Can't convert void to java.lang.String.
                   trans.setString(7, trans.setString(7, Long.toString(new java.util.Date().getTime())));
                                                     ^

0
 

Author Comment

by:VWrestle97
ID: 8179382
Sorry about that.... I saw my error
0
 

Author Comment

by:VWrestle97
ID: 8179431
How can I pass the exact same stamp time to both databases with out having the other database calling the function for each product .... so that I can stop it from generating a new stamp time for each product within the same order.
0
 
LVL 92

Expert Comment

by:objects
ID: 8179489
You store the timestamp and use it all both insert's:

String tranid = Long.toString(new java.util.Date().getTime());

cust.setString(7, tranid);

...


order.setString(x, tranid);

0
 

Author Comment

by:VWrestle97
ID: 8182492
As far as the database connection goes, is it possible to make the DBQ of ..........

(*.mdb)};DBQ=D:\\ProgrammingLanguagefiles\\Borland\\TogetherControl6\\myDatabases\\dvdshopdb.mdb");

relative to just my project rather than making it absoulte?



0
 

Author Comment

by:VWrestle97
ID: 8182502
Is there a function that I can use to post the time/date?
0
 

Author Comment

by:VWrestle97
ID: 8182532
How do I post something on a web page comming from the database.... can you give me an example from my project?
0
 
LVL 92

Expert Comment

by:objects
ID: 8184273
> relative to just my project rather than making it absoulte?

What you would do is create a DSN and specify it's name in your connection string.

> Is there a function that I can use to post the time/date?

Not sure what you mean, can you explain further.

> How do I post something on a web page comming from the database

You would do a select on the database and display that to your page.

<%

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=D:\\development\\www.objects.com.au\\new\\jsp\\dvdshopdb.mdb");

    java.sql.PreparedStatement q = connection.prepareStatement ("select * from Customers");
    java.sql.ResultSet rs = q.executeQuery();
  %>
  <table>
   <tr>
     <th>Name</th>
     <th>Credit Card#</th>
   </tr>
  <%
    while (rs.next())
    {
  %>
  <tr>
    <td><%= rs.getObject("name") %></td>
    <td><%= rs.getObject("creditcard") %></td>
  </tr>
  <%
    }
  %>
</table>
0
 

Author Comment

by:VWrestle97
ID: 8184764
>What you would do is create a DSN and specify it's name in your connection string.

how do you create a DSN?

>Not sure what you mean, can you explain further.

does java have an api/command that I can use to state the time of purchase ex.  Friday, March 21, 2003 and the time of the day?

0
 
LVL 92

Expert Comment

by:objects
ID: 8184795
To create a DSN:

Control Panel>Administrative Tools>Data Sources (ODBC)

The DateFormat and SimpleDateFormat classes provide support for formatting dates to your need:

<%
java.util.Date today = new java.util.Date();
java.text.DateFormat df = java.text.DateFormat.getDateInstance(java.text.DateFormat.LONG);
java.text.DateFormat tf = java.text.DateFormat.getTimeInstance(java.text.DateFormat.LONG);
%>

Date: <%= df.format(today) %><br>
Time: <%= tf.format(today) %><br>



0
 

Author Comment

by:VWrestle97
ID: 8193330
Can you clearify some things with me regarding my project?....

1)When is an import statement needed....
       <%@ page import="dvdshop.DVDProductBean" %>...

       is it only needed when I am using a tag from my tld file, and not from a bean tag?

2)Does a jsp:useBean , useProperty, or setProperty require an import class statement like the one above?

3)can you better explain the purpose for className="DVDProductBean" of the code below:

 <dvd:loop name="cart" property="products" loopId="product" className="DVDProductBean">

4)I noticed that a useBean was not used earlier in the code for the className DVDProductBean... Is that because it is declared in the code below... so that it takes care of the jsp:useBean?

<dvd:useProperty id="product" name="catalog" property="product"
 arg='<%= request.getParameter("id") %>'
 className="dvdshop.DVDProductBean" />



0
 
LVL 92

Expert Comment

by:objects
ID: 8193400
1) It is needed if you want to use the class name without specifying the package name.

2) No, but if there isn't one you need to include the fully classname include package name.

3) It defined the class of the object instance 'product'

4) Yes that tag handles creating the bean instance.

0
 

Author Comment

by:VWrestle97
ID: 8193447
>3) It defined the class of the object instance 'product'

what about the property="products".. does that also require the className?

>2) No, but if there isn't one you need to include the fully classname include package name.

so is it only a choice between either an include statement or a <jsp:    > statement?
Is the jsp:useBean , useProperty, or setProperty an example of a fully classname include package name?

ADDITIONAL QUESTION
3)What is the purpose of the encodeURL  tag in the code below: and when is the param tag needed?


<a href="
          <dvd:encodeURL url="DVDproduct.jsp">
          <dvd:param name="id" value="<%= product.getId() %>"/>
          </dvd:encodeURL>"><%= product.getName() %>
          </a>



0
 
LVL 92

Expert Comment

by:objects
ID: 8193499
> does that also require the className?

No, it uses the existing bean named 'cart'.

> so is it only a choice between either an include statement or a <jsp:    > statement?

No it is a choice of using an import or specifying the package name whenever you use the classname:

eg. with import you could do:

<dvd:useProperty id="product" name="catalog" property="product"
arg='<%= request.getParameter("id") %>'
className="DVDProductBean" />

without import you would need:

<dvd:useProperty id="product" name="catalog" property="product"
arg='<%= request.getParameter("id") %>'
className="dvdshop.DVDProductBean" />

> )What is the purpose of the encodeURL  tag in the code below: and when is the param tag needed?

To encode the URL converting things like spaces etc.
The param tag is need when you need to include a parameter in the url.






0
 

Author Comment

by:VWrestle97
ID: 8193705
>To encode the URL converting things like spaces etc.

I don't see any spaces in my URL?

couldn't I have used...
 <a href="AddToCart.jsp?id=<%= product.getId() %>">Add
        to Cart</a>
instead of ....
<a href="
         <dvd:encodeURL url="DVDproduct.jsp">
         <dvd:param name="id" value="<%= product.getId() %>"/>
         </dvd:encodeURL>"><%= product.getName() %>
         </a>
0
 
LVL 92

Expert Comment

by:objects
ID: 8197952
In that case yes you could have. Encoding a URL is used if there is a possibility of invalid characters being used in URL.
0
 

Author Comment

by:VWrestle97
ID: 8199740
I there a limit to how many parameters that I can pass with a single
<a href> statement
0
 

Author Comment

by:VWrestle97
ID: 8199741
is ther a limit?
0
 
LVL 92

Expert Comment

by:objects
ID: 8199776
no.
0
 

Author Comment

by:VWrestle97
ID: 8200641
how would you separate multiple parameters in a single href statement?
0
 

Author Comment

by:VWrestle97
ID: 8200658
is it separated by a '?'
0
 
LVL 92

Expert Comment

by:objects
ID: 8200665
No a &, but the tag handles that for you.
0
 

Author Comment

by:VWrestle97
ID: 8200800
can you show me an example of a href using the &....considering that it won't be using the tag handler
0
 

Author Comment

by:VWrestle97
ID: 8200838
why would catalog be a vector?
0
 
LVL 92

Expert Comment

by:objects
ID: 8200839
sure :)

<a href="xyz.jsp?a=1&b=3">click here</a>
0
 
LVL 92

Expert Comment

by:objects
ID: 8200888
> why would catalog be a vector?

Because it stores a number of different products.
0
 

Author Comment

by:VWrestle97
ID: 8200906
is it possible to declare the scope of a bean in a setProperty or useProperty, instead of using a useBean
0
 
LVL 92

Expert Comment

by:objects
ID: 8200927
No it isn't.
0
 

Author Comment

by:VWrestle97
ID: 8201005
can you tell me what this code does for each command?


<dvd:useProperty id="product" name="catalog" property="product"
 arg='<%= request.getParameter("id") %>'
 className="dvdshop.DVDProductBean" />
0
 

Author Comment

by:VWrestle97
ID: 8201048
from comparing the two codes below... can you tell me the purpose of the "this."  when do you use it?


public void setRemove(DVDProductBean product) {
       cart.remove(product);
  }

 public void setName(String name) {
       this.name = name;
   }
   
0
 

Author Comment

by:VWrestle97
ID: 8201067
public void setValue(String value_) {
       value = this.value_ = value_;
   }  


What does the second line of code do.. and what is the purpose of having the "_" after value_
0
 
LVL 92

Expert Comment

by:objects
ID: 8201074
It is needed in this instance to identify the class member variable 'name' instead of the local parameter of the same name.
It is used in cases like this, or when you need a reference to the current object instance.
0
 

Author Comment

by:VWrestle97
ID: 8205304
what piece of code makes my program substitue the use for cookies.... is it the scope of the useBean or is there more to it?
0
 

Author Comment

by:VWrestle97
ID: 8205388
....which code makes each session unique for each customer ?


If I wanted to make by site secure...what would I need to include?
0
 
LVL 92

Expert Comment

by:objects
ID: 8205804
Generating the session id is handled by Tomcat. And the managing of the session id on the client side is done with cookies.

If you are referring to making the network traffic between the client and server secure then you would need to use https instead of http. This would only involve a change to the configuration of the server, and not to your code.
0
 
LVL 92

Expert Comment

by:objects
ID: 8205823
Thanks for the points :-)

I'm no longer answering questions in this forum, but am still answering in the "Java Programming" forum. So post any new questions there if you want me to assist you further.
http://www.experts-exchange.com/Programming/Programming_Languages/Java/
There are also a lot more experts than there are in this forum to assist you.

Hope I can help you again :-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This month, Experts Exchange’s free Course of the Month is focused on CompTIA IT Fundamentals.
I don't pretend to be an expert at this, but I have found a few things that are useful. I hope that sharing them here will help others, so they will not have to face some rather hard choices. Since I felt this to be a topic of enough importance and…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month8 days, 16 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question