473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Servlet Problem

24
Please I need help with this so bad. I have been struggling with it for 2weeks now.

on line 206, I what to create a link that will direct you to the detail of the chosen items, like in the screenshot



Yes, I know the rules. This is a home and the class is for graduate student and I am an undergraduate. the teacher doesn't render any help whatsoever. check the comment on her rating,the last comment is the class I am taking with her.

http://209.85.165.104/search?q=cache...ient=firefox-a

anyone that feels like giving me a personal assistant can pm me.
Thanks in Advance

Expand|Select|Wrap|Line Numbers
  1. /*
  2.  * OrderPage.java
  3.  *
  4.  * Created on October 16, 2007, 12:31 PM
  5.  */
  6.  
  7. package ITIS5166;
  8.  
  9. import java.io.*;
  10. import javax.servlet.*;
  11. import javax.servlet.http.*;
  12. import java.util.*;
  13. import java.text.*;
  14.  
  15. /** Shows all items currently in ShoppingCart. Clients
  16.  *  have their own session that keeps track of which
  17.  *  ShoppingCart is theirs. If this is their first visit
  18.  *  to the order page, a new shopping cart is created.
  19.  *  Usually, people come to this page by way of a page
  20.  *  showing catalog entries, so this page adds an additional
  21.  *  item to the shopping cart. But users can also
  22.  *  bookmark this page, access it from their history list,
  23.  *  or be sent back to it by clicking on the "Update Order"
  24.  *  button after changing the number of items ordered.
  25.  *  <P>
  26.  *  Taken from Core Servlets and JavaServer Pages 2nd Edition
  27.  *  from Prentice Hall and Sun Microsystems Press,
  28.  *  http://www.coreservlets.com/.
  29.  *  &copy; 2003 Marty Hall; may be freely used or adapted.
  30.  */
  31.  
  32. public class ShopCartServletHW3 extends HttpServlet {
  33.   public void doGet(HttpServletRequest request,
  34.                     HttpServletResponse response)
  35.       throws ServletException, IOException {
  36.     HttpSession session = request.getSession();
  37.     ShopCartDataHW3 cart;
  38.     synchronized(session) {
  39.       cart = (ShopCartDataHW3)session.getAttribute("ShopCartDataHW3");
  40.       // New visitors get a fresh shopping cart.
  41.       // Previous visitors keep using their existing cart.
  42.       if (cart == null){
  43.           cart = new ShopCartDataHW3();
  44.           session.setAttribute("ShopCartDataHW3", cart);
  45.       }
  46.       String itemID = request.getParameter("itemID");
  47.       if (itemID != null) {
  48.           String numItemsString = request.getParameter("numItems");
  49.           if (numItemsString == null) {
  50.               cart.addItem(itemID);
  51.         } else {
  52.           // If request specified an ID and number, then
  53.           // customers came here via an "Update Order" button
  54.           // after changing the number of items in order.
  55.           // Note that specifying a number of 0 results
  56.           // in item being deleted from cart.
  57.           int numItems;
  58.           try {
  59.             numItems = Integer.parseInt(numItemsString);
  60.           } catch(NumberFormatException nfe) {
  61.             numItems = 1;
  62.           }
  63.           cart.setNumOrdered(itemID, numItems);
  64.         }
  65.       }
  66.     }
  67.     // Whether or not the customer changed the order, show
  68.     // order status.
  69.     String straddress=request.getParameter("address");
  70.     String strshippingtype=request.getParameter("shippingtype");
  71.     String strcardtype=request.getParameter("cardtype");
  72.     String strcardnum=request.getParameter("cardnum");
  73.     String strcardname=request.getParameter("personname");
  74.  
  75.     response.setContentType("text/html");
  76.     PrintWriter out = response.getWriter();
  77.     String title = "Status of Your Order";
  78.     String docType =
  79.       "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
  80.       "Transitional//EN\">\n";
  81.     out.println(docType +
  82.                 "<HTML>\n" +
  83.                 "<HEAD><TITLE>" + title + "</TITLE></HEAD>\n" +
  84.                 "<BODY BGCOLOR=\"#FDF5E6\">\n" +
  85.                 "<H1 ALIGN=\"CENTER\">" + title + "</H1>");
  86.     synchronized(session) {
  87.       List itemsOrdered = cart.getItemsOrdered();
  88.       if (itemsOrdered.size() == 0) {
  89.         out.println("<H2><I>No items in your cart...</I></H2>");
  90.         out.println
  91.           ("<TABLE BORDER=1 ALIGN=\"CENTER\">\n" +
  92.            "<TR BGCOLOR=\"#FFAD00\">\n" +
  93.            "  <TH>Item ID<TH>Description\n" +
  94.            "  <TH>Unit Cost<TH>Number<TH>Total Cost");
  95.  
  96.           out.println            
  97.             ("<TR>\n" +
  98.              "  <TR bgcolor=#339900>" +
  99.              "  <TD height=30> Shipping Information </TD></TR>" +
  100.              "  <TR><TD WIDTH=200>" +
  101.              "  <textarea name=address cols=50 rows=4></textarea></form></td>" +
  102.              "  <TD><P>"+"<LABEL>" +
  103.              "  <input type=radio name=shippingtype value=UPS Grounds>" +
  104.              "  UPS Ground </label><br>" +
  105.              "  <label>" +
  106.                   "<input type=radio name=shippingtype value=UPS 2nd Day Air>" +
  107.                   "UPS 2nd Day Air </label><br>" +
  108.                   "<label><input type=radio name=shipping values=FedEx Priority>" +
  109.                   "FedEx Priority </label><br>" +
  110.                   "<label><input type=radio name=shippingtype value=FedEx Ultra>" +
  111.                   "FedEx Ultra</label></p></form></td></tr>" +
  112.                   "<tr bgcolor=#339900>" +
  113.                   "<td height=30>Credit Card Information</td></tr>" +
  114.                   "<tr><td height=40>Card Type: </td>" +
  115.                   "<td colspan=4>" +
  116.                   "<select name=cardtype value=visa>" +
  117.                   "<option selected value=visa>Visa</option>" +
  118.                   "<option value=MasterCard>MasterCard</option>" +
  119.                   "<option value=America Express>America Express</option>" +
  120.                   "<select></form></td></tr>" +
  121.                   "<td height=30>Card Number:</td>" +
  122.                   "<td colspan=4><input type=text name=cardnum> </form></td></tr>" +
  123.                   "</form></td></tr>" +
  124.                   "<tr><t height=30>Cardholder Name:</td>" +
  125.                   "<td colspan=4><input type=text name=personname></form></td></tr><br>");
  126.       }
  127.  
  128.       else {
  129.           out.println ("<table border=1>" +
  130.                   "<tr bgcolor=#339900>" +
  131.                   "<th width=90>Item ID<th>Description" +
  132.                   "<th>Unit Cost <th>Number<th>Total Cost");
  133.           ItemOrder order;
  134.  
  135.           NumberFormat formatter =
  136.           NumberFormat.getCurrencyInstance();
  137.         // For each entry in shopping cart, make
  138.         // table row showing ID, description, per-item
  139.         // cost, number ordered, and total cost.
  140.         // Put number ordered in textfield that user
  141.         // can change, with "Update Order" button next
  142.         // to it, which resubmits to this same page
  143.         // but specifying a different number of items.
  144.         for(int i=0; i<itemsOrdered.size(); i++) {
  145.           order = (ItemOrder)itemsOrdered.get(i);
  146.           out.println
  147.             ("<TR>\n" +
  148.              "  <TD>" + order.getItemID() + "\n" +
  149.              "  <TD>" + order.getShortDescription() + "\n" +
  150.              "  <TD>" +
  151.              formatter.format(order.getUnitCost()) + "\n" +
  152.              "  <TD>" +
  153.              "<FORM>\n" +  // Submit to current URL
  154.              "<INPUT TYPE=\"HIDDEN\" NAME=\"itemID\"\n" +
  155.              "       VALUE=\"" + order.getItemID() + "\">\n" +
  156.              "<INPUT TYPE=\"TEXT\" NAME=\"numItems\"\n" +
  157.              "       SIZE=3 VALUE=\"" + 
  158.              order.getNumItems() + "\">\n" +
  159.              "<SMALL>\n" +
  160.              "<INPUT TYPE=\"SUBMIT\"\n "+
  161.              "       VALUE=\"Update Order\">\n" +
  162.              "</SMALL>\n" +
  163.              "</FORM>\n" +
  164.              "  <TD>" +
  165.              formatter.format(order.getTotalCost()));
  166.         }
  167.  
  168.    if ((straddress!=null)&&(strshippingtype!=null)
  169.        &&(strcardtype!=null)&&(strcardnum!=null)&&(strcardname!=null))
  170.    {
  171.               out.println("<form action=PurchConfServletHW3 methed=Get>");
  172.    }
  173.    else{
  174.               out.println("<form action=ShopCartServletHW3 method=Get>");
  175.               out.println("Please enter your Information");
  176.    }
  177.           out.println(
  178.  
  179.                   "</tr>"+
  180.                   "<tr bgcolor=#339900><td height=30 colspan=5>" +
  181.                   "Shipping Information</td></tr>" +
  182.                   "<tr><td with=200><textarea name=address cols=50 rows=4></textarea></td>" +
  183.                   "<td colspan=4><p>"+"<label><br />" +
  184.                   "<input type=radio name=shippingtype value=UPS Ground>" +
  185.                   "UPS Ground </label><br>" +
  186.                   "<label><input type=raio name=shippingtype value=UPS 2nd Day Air>" +
  187.                   "UPS 2nd Day Air </label>" +
  188.                   "<label><input type=radio name=shippingtype value=FedEx Priority>" +
  189.                   "FedEx Priority <label>" +
  190.                   "<label><input type=radio name=shippingtype value=FedEx Ultra>" +
  191.                   "FedEx Ultra </label></p></td></tr>" +
  192.                   "<tr bgcolor=#339900><td height=30 colspan=5>" +
  193.                   "Credit Card Information</td></tr>" +
  194.                   "<tr><td height=30>Card Type:</td>" +
  195.                   "<td colspan=4><select anme=cardtype value=visa>" +
  196.                   "option selected value=Visa>Visa</option>" +
  197.                   "option value=MasterCard>MasterCard</option>" +
  198.                   "option value=America Express>America Express</option></select></td></tr>" +
  199.                   "<tr><td height=30>Card Number:</td>" +
  200.                   "<td colspan=4><input type=text name=cardnum></td></tr></td></tr>" +
  201.                   "<tr><td height=30>Cardholder Name:</td>" +
  202.                   "<td colspan=4><input type=text name=personname></td></tr>" +
  203.                   "tr bgcolor=#339900><td height=30><input type=submit name=Sumbit4 value=Purchase></td></tr>" +
  204.                   "</form>");
  205.         String checkoutURL =
  206.           response.encodeURL("../Checkout.html");
  207.         // "Proceed to Checkout" button below table
  208.         out.println
  209.           ("</TABLE>\n" +
  210.            "<FORM ACTION=\"" + checkoutURL + "\">\n" +
  211.            "<BIG><CENTER>\n" +
  212.            "<INPUT TYPE=\"SUBMIT\"\n" +
  213.            "       VALUE=\"Proceed to Checkout\">\n" +
  214.            "</CENTER></BIG></FORM>");
  215.       }
  216.       out.println("</BODY></HTML>");
  217.     }
  218.   }
  219.  
  220.   }
  221.  
Oct 19 '07 #1
3 1631
ak1dnar
1,584 Expert 1GB
wrap your item description values with a anchor tag and pass the relevant URL parameters with the links to product_details page. all it depends on the way you have created your pages. for a example let's assume that these are your link to products on the description column on your shopping cart;

<a href="product_details.jsp?item_id=1001">Item 1001 description</a>
<a href="product_details.jsp?item_id=1002">Item 1002 description</a>

Then from the product_details.jsp get the "item_id" display the records for the item.
Oct 20 '07 #2
JosAH
11,448 Expert 8TB
I'll move your question over to the Java Forum section.

kind regards,

Jos
Oct 21 '07 #3
JosAH
11,448 Expert 8TB
Why don't you use a simple JSP page for the actual html output? If you try to
output everything from your single Servlet it becomes an untangible mess as
you can see already.

kind regards,

Jos
Oct 21 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: TheLetti | last post by:
Hy! I've just downloaded the latest Java 2 SDK (j2sdk1.4.2_01). For my surprise in this version the servlet-classes are not integrated (e.g. the class javax.servlet). So I found all the...
6
by: alan | last post by:
Dear all, I have a servlet problem. When I modified my java servlet program and then uploaded it to my web hosting server, then I start my web browser(I.E) to see the result. But it loaded...
2
by: Rose Girl | last post by:
Hi Need some help on javascript. I need to know how to call a servlet from a javascript function. web-inf (jboss) path for servlet is: com.purpleace.ripple.admin.contacts.servlet.AdminReport...
1
by: sang | last post by:
Hi I prepared a program for Email Integration. That is email send to others through servlet's. I gave the code but it has some error in my code. Please check the code and give the feedback. ...
1
by: elsheh | last post by:
I am trying to develop JavaServlet application using Apache Tomcat server. My application consists of two servlets and Java class for pooling connection. I need to include all my servlets in the same...
6
by: Sushmita | last post by:
hi all, I have wrriten code for a small web application. From my JSP page i am not able to call the servlet.. its throwing an exception. "javax.servlet.ServletException: Wrapper cannot find...
2
by: dmstn | last post by:
Hey! I've got a little problem. I have to make a web site for a university essay. I curently have to create a search engine. Users can enter a hotel name in a search bar and results have to appear in...
1
by: shiyamala | last post by:
Hi i am shiyam, i am having some problem in java, i am basic java programmer. i have to write one program is writing the data into textfile name "newfile.txt" from one servlet and read it from...
3
by: krishna81m | last post by:
Hello, I am looking for a solution to update a .jsp page (kind of progress bar) which shows current progress in a huge simulation when users have to wait for longer periods and the way to do it...
9
by: mjahabarsadiq | last post by:
Hi I have created a servlet that is to be started at the server startup. And I got it. In that I have created a object of another class and set it as a session attribute. What I am trying is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.