473,666 Members | 2,225 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Servlet Problem

24 New Member
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 1643
ak1dnar
1,584 Recognized Expert Top Contributor
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_d etails.jsp?item _id=1001">Item 1001 description</a>
<a href="product_d etails.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 Recognized Expert MVP
I'll move your question over to the Java Forum section.

kind regards,

Jos
Oct 21 '07 #3
JosAH
11,448 Recognized Expert MVP
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
4795
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 servlet-classes I needed on the java.sun.com-Homepage and downloaded the javax.servlet-Package. (Maybe this file-description may help you understanding my problem:
6
3175
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 the previous java servlet class program. After several days, these new classes file can be refreshed on browser. I want to know how I can make sure I always see the most update
2
2464
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 web xml <servet-mapping> is :
1
2247
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. The Servlet code: import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class MailServlet extends HttpServlet {
1
1389
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 package (let’s call it, proj). The task of the first servlet is to build up an Web HTML form for gathering data. The second servlet does validation and store entry data to Database. The problem is: At first call for first servlet the application...
6
4467
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 servlet class servlet.IssueTrackerControllerServlet or a class it depends on org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39) ...
2
2614
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 another screen. All of this has to be done with java servlets. I think there's something I don't see and it's wrong. My problem is that anything I enter in the search bar appears as a result in the results page, even if there's not such a name in...
1
2141
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 another servlet its work but i want to know hw to deploy the readed input from textfile is displayed in jsp through servlet2. here is my code import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import...
3
1556
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 was have the jsp page refresh often and the page data update by a bean containing the properties file details. The main servlet class continously running on the server regularly updates the properties file. I am currently using a properties file,...
9
3171
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 to get the object in a jsp page. Following are the codes.
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8866
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8550
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8639
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7385
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6192
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4366
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.