Displaying a table correctly?

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

30 Replies - 1642 Views - Last Post: 12 February 2012 - 11:07 AM

#1 Java Neil  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 140
  • Joined: 26-March 11

Displaying a table correctly?

Posted 10 February 2012 - 03:45 PM

Hi guys...I hope this is the right place to ask this question. I have a Servlet that I'm working on and I'm having a hard time with the Java portion of the code. I am trying to display a table for a shopping cart checkout. The problem is the rows and columns are not working out correctly.

Here is the portion of the code that's not doing what I want.

            for(String item: previousNAME) {
               writer.write("<TR><TD>" + item + "</TD>");
            }
         
            for(String itemNUM: previousID_NUM) {
               writer.write("<TD>" + itemNUM + "</TD>");
            }
         
            for(String itemCOLOR: previousADDITIONALINFO) {
               writer.write("<TD>" + itemCOLOR + "</TD>");
            }
         
            for(String itemSIZE: previousADDITIONALINFO2) {
               writer.write("<TD>" + itemSIZE + "</TD>");
            }
         
            for(String itemCOUNT: previousQUANTITY) {
               writer.write("<TD>" + itemCOUNT+ "</TD>");
            }
         
            for(String itemCOST: previousPRICE) {
               writer.write("<TD>" + itemCOST + "</TD>");
            }
         
            for(String itemSEND: previousSHIPPING) {
               writer.write("<TD>" + itemSEND + "</TD>");
            }
            
            writer.write("<TD>$" +  Total  + "</TD</TR>");


this is my code for getting the data to the for loops.

         synchronized(session) {
            @SuppressWarnings("unchecked")
                  List<String> previousNAME =
                  (List<String>)session.getAttribute("previousNAME");
               
            if (previousNAME== null) {
               previousNAME = new ArrayList<String>();
            }
            String NAME= request.getParameter("NAME");
            if ((NAME != null) &&
               (!NAME.trim().equals(""))) {
               previousNAME.add(NAME);
            }
            session.setAttribute("previousNAME", previousNAME);
            
            
            @SuppressWarnings("unchecked")
                  List<String> previousID_NUM =
                  (List<String>)session.getAttribute("previousID_NUM");
               
            if (previousID_NUM== null) {
               previousID_NUM = new ArrayList<String>();
            }
            String ID_NUM= request.getParameter("ID_NUM");
            if ((ID_NUM != null) &&
               (!ID_NUM.trim().equals(""))) {
               previousID_NUM.add(ID_NUM);
            }
            session.setAttribute("previousID_NUM", previousID_NUM);
            
         	
            @SuppressWarnings("unchecked")
                  List<String> previousADDITIONALINFO =
                  (List<String>)session.getAttribute("previousADDITIONALINFO");
               
            if (previousADDITIONALINFO== null) {
               previousADDITIONALINFO = new ArrayList<String>();
            }
            String ADDITIONALINFO= request.getParameter("ADDITIONALINFO");
            if ((ADDITIONALINFO != null) &&
               (!ADDITIONALINFO.trim().equals(""))) {
               previousADDITIONALINFO.add(ADDITIONALINFO);
            }
            session.setAttribute("previousADDITIONALINFO", previousADDITIONALINFO);
            
         	
            @SuppressWarnings("unchecked")
                  List<String> previousADDITIONALINFO2 =
                  (List<String>)session.getAttribute("previousADDITIONALINFO2");
               
            if (previousADDITIONALINFO2== null) {
               previousADDITIONALINFO2 = new ArrayList<String>();
            }
            String ADDITIONALINFO2= request.getParameter("ADDITIONALINFO2");
            if ((ADDITIONALINFO2 != null) &&
               (!ADDITIONALINFO2.trim().equals(""))) {
               previousADDITIONALINFO2.add(ADDITIONALINFO2);
            }
            session.setAttribute("previousADDITIONALINFO2", previousADDITIONALINFO2);
            
         	
            @SuppressWarnings("unchecked")
                  List<String> previousQUANTITY =
                  (List<String>)session.getAttribute("previousQUANTITY");
               
            if (previousQUANTITY== null) {
               previousQUANTITY = new ArrayList<String>();
            }
            String QUANTITY= request.getParameter("QUANTITY");
            if ((QUANTITY != null) &&
               (!QUANTITY.trim().equals(""))) {
               previousQUANTITY.add(QUANTITY);
            }
            session.setAttribute("previousQUANTITY", previousQUANTITY);
            
         	
            @SuppressWarnings("unchecked")
                  List<String> previousPRICE =
                  (List<String>)session.getAttribute("previousPRICE");
               
            if (previousPRICE== null) {
               previousPRICE = new ArrayList<String>();
            }
            String PRICE= request.getParameter("PRICE");
            if ((PRICE != null) &&
               (!PRICE.trim().equals(""))) {
               previousPRICE.add(PRICE);
            }
            session.setAttribute("previousPRICE", previousPRICE);
            
         	
            @SuppressWarnings("unchecked")
                  List<String> previousSHIPPING =
                  (List<String>)session.getAttribute("previousSHIPPING");
               
            if (previousSHIPPING== null) {
               previousSHIPPING = new ArrayList<String>();
            }
            String SHIPPING= request.getParameter("SHIPPING");
            if ((SHIPPING != null) &&
               (!SHIPPING.trim().equals(""))) {
               previousSHIPPING.add(SHIPPING);
            }
            session.setAttribute("previousSHIPPING", previousSHIPPING);


I've attached two partial screen shots to show first what I need the output to be and the second one what I'm getting after I visit the page a second time.

Any help would be great. I'm sure it's something simple, but I have been trying to solve this on my on for about four hours with no luck.

Thanks

Attached image(s)

  • Attached Image
  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Displaying a table correctly?

#2 Java Neil  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 140
  • Joined: 26-March 11

Re: Displaying a table correctly?

Posted 10 February 2012 - 10:04 PM

Hello Java World. I need some pointers on how to retrieve data from multiple "for loops" to create one string. Here is the snippet of code.

            for(String item: previousNAME) {
               writer.write("<TD>" + item + "</TD>");
            }
         
            for(String itemNUM: previousID_NUM) {
               writer.write("<TD>" + itemNUM + "</TD>");
            }
         
            for(String itemCOLOR: previousADDITIONALINFO) {
               writer.write("<TD>" + itemCOLOR + "</TD>");
            }
         
            for(String itemSIZE: previousADDITIONALINFO2) {
               writer.write("<TD>" + itemSIZE + "</TD>");
            }
         
            for(String itemCOUNT: previousQUANTITY) {
               writer.write("<TD>" + itemCOUNT + "</TD>");
            }
         
            for(String itemCOST: previousPRICE) {
               writer.write("<TD>" + itemCOST + "</TD>");
            }
         
            for(String itemSEND: previousSHIPPING) {
               writer.write("<TD>" + itemSEND + "</TD>");
            }


I'm sure it's something simple but for the life of me, I can't find it
Was This Post Helpful? 0
  • +
  • -

#3 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7293
  • View blog
  • Posts: 12,114
  • Joined: 19-March 11

Re: Displaying a table correctly?

Posted 10 February 2012 - 10:16 PM

I'm not sure what's going on in your sample code, honestly, or what you're trying to actually accomplish here.

Clearly you're assembling an HTML table, but I get the notion that you want something like this:

<tr><td> NAME </TD> <td> ID NUMBER </td> <td> color</td> <td> size</td> [...] </tr>
<tr><td> NAME </TD> <td> ID NUMBER </td> <td> color</td> <td> size</td> [...] </tr>
<tr><td> NAME </TD> <td> ID NUMBER </td> <td> color</td> <td> size</td> [...] </tr>

but what you're going to get here is something like this:


<td> NAME </TD> <td> NAME </TD> <td> NAME </TD> <td> NAME </TD> <td> ID NUMBER </td><td> ID NUMBER </td><td> ID NUMBER </td><td> ID NUMBER </td><td> color</td><td> color</td><td> color</td><td> color</td>[...]

Am I on the right track here?
Was This Post Helpful? 0
  • +
  • -

#4 Java Neil  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 140
  • Joined: 26-March 11

Re: Displaying a table correctly?

Posted 10 February 2012 - 10:26 PM

View Postjon.kiparsky, on 10 February 2012 - 10:16 PM, said:

I'm not sure what's going on in your sample code, honestly, or what you're trying to actually accomplish here.

Clearly you're assembling an HTML table, but I get the notion that you want something like this:

<tr><td> NAME </TD> <td> ID NUMBER </td> <td> color</td> <td> size</td> [...] </tr>
<tr><td> NAME </TD> <td> ID NUMBER </td> <td> color</td> <td> size</td> [...] </tr>
<tr><td> NAME </TD> <td> ID NUMBER </td> <td> color</td> <td> size</td> [...] </tr>

but what you're going to get here is something like this:


<td> NAME </TD> <td> NAME </TD> <td> NAME </TD> <td> NAME </TD> <td> ID NUMBER </td><td> ID NUMBER </td><td> ID NUMBER </td><td> ID NUMBER </td><td> color</td><td> color</td><td> color</td><td> color</td>[...]

Am I on the right track here?


Yes, you are correct sir! Any ideas?
Was This Post Helpful? 0
  • +
  • -

#5 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7293
  • View blog
  • Posts: 12,114
  • Joined: 19-March 11

Re: Displaying a table correctly?

Posted 10 February 2012 - 11:08 PM

*
POPULAR

Sure, plenty of 'em. I don't know which ones are good ones because there's a lot of critical information missing, but it's looking to me like you have a lot of product information in a series of parallel arrays. This is difficult to deal with gracefully, but you'd probably do something like this to start with:

StringBuilder sb = new StringBuilder();

for (int i = 0; i < previousName.length; i++)
{
sb.append("<tr>");

   sb.append("<TD>" + previousName[i] + "</TD>");
sb.append("<TD>" + previousID_NUM[i] + "</TD>");

sb.append("<TD>" + previousADDITIONALINFO[i] + "</TD>");
sb.append("<TD>" + previousADDITIONALINFO2[i] + "</TD>");
sb.append("<TD>" + previousQUANTITY[i] + "</TD>");
sb.append("<TD>" + previousPRICE[i] + "</TD>");
sb.append("<TD>" + previousSHIPPING[i] + "</TD>");
sb.append("</tr> \n");  // newline added for a bit of readability

writer.write(sb.toString()); // you could do this outside the loop as well
}




This is not a very good solution, but I think it's in line with the data as you're currently representing it.

There are probably better solutions out there. What might they look like? Well, the best ideas would reflect the structure you're trying to build. A Table has Rows and Rows have Cells. Cells have text in them. So maybe you think about writing some classes.

What if you could do something like

Table table = new Table();

for (int i = 0; i < previousName.length; i++)
{
Row r = new Row();
r.add(new Cell( previousName[i]);
r.add(new Cell( previousID_NUM[i] );

r.add(new Cell(  previousADDITIONALINFO[i] );
r.add(new Cell(  previousADDITIONALINFO2[i] );
r.add(new Cell(  previousQUANTITY[i] );
r.add(new Cell(  previousPRICE[i] );
r.add(new Cell(  previousSHIPPING[i] );

}



Isn't that a bit nicer? Assuming a Table knows how to write itself out to a text file, which means that Tables call Rows and Rows call Cells, and cells return "<td> content </td>" and rows return "<tr>[CELLS HERE]</tr>" and Tables give you "<table>[ROWS HERE]</table>", then you're in business.

Of course, if you changed your data design a little, you could have an InventoryItem class. Each InventoryItem has name, number, size, etc as fields. If you write accessors for the fieldss, you could use the accessors in the same fashion as above:

Table table = new Table();

for (InventoryItem i: items) //we're back to an enhanced loop, yay!
{
Row r = new Row();
r.add(new Cell( i.getName());
r.add(new Cell( i.getID_num() );
 
...
}



or better still, you could teach an Item how to spit out a Row that represents itself, by writing this into the InventoryItem class.

Now it's easier still:

Table table = new Table();

for (InventoryItem i: items) //we're back to an enhanced loop, yay!
{
  Row r = new Row(i);
}



And life's looking better and better.

When you learn a little more about inheritance, we can talk about further enhancements - InventoryItem really ought to be an interface, and then you're really in business. You might want to list hats, shoes, handkerchiefs, and pocket watches (for the well-turned out gentleman you're catering to in your online shop). All of these have different characteristics, but as items in your catalog, they all need to have the same sorts of behaviour. Interfaces allow you to make this happen.

I realize that I've gone somewhat beyond the scope of your original inquiry, but make use of what you can - the rest will come back to make sense as you dig further into the language.

This post has been edited by jon.kiparsky: 10 February 2012 - 11:12 PM

Was This Post Helpful? 5
  • +
  • -

#6 Java Neil  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 140
  • Joined: 26-March 11

Re: Displaying a table correctly?

Posted 10 February 2012 - 11:51 PM

Wow! That's a lot to think about. I'll be doing a lot of reading based off of what you just explained.

Perhaps I should post the full code so you can see my newby logic. The examples that you were so kind to post did not compile with my code for some reason. I've been going over this code for two days now, so it's entirely possible that my eyes are not working properly anymore.

Anyway...

   import java.io.IOException;
   import java.io.PrintWriter;
   import java.util.Arrays;  
   import java.util.List;  
   import java.util.ArrayList;
   import javax.servlet.ServletException;
   import javax.servlet.http.HttpServlet;
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
   import javax.servlet.http.HttpSession;
 
   public class CartServlet extends HttpServlet {
   
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      
         HttpSession session = request.getSession();
      
         synchronized(session) {
            @SuppressWarnings("unchecked")
                  List<String> previousNAME =
                  (List<String>)session.getAttribute("previousNAME");
               
            if (previousNAME== null) {
               previousNAME = new ArrayList<String>();
            }
            String NAME= request.getParameter("NAME");
            if ((NAME != null) &&
               (!NAME.trim().equals(""))) {
               previousNAME.add(NAME);
            }
            session.setAttribute("previousNAME", previousNAME);
            
            
            @SuppressWarnings("unchecked")
                  List<String> previousID_NUM =
                  (List<String>)session.getAttribute("previousID_NUM");
               
            if (previousID_NUM== null) {
               previousID_NUM = new ArrayList<String>();
            }
            String ID_NUM= request.getParameter("ID_NUM");
            if ((ID_NUM != null) &&
               (!ID_NUM.trim().equals(""))) {
               previousID_NUM.add(ID_NUM);
            }
            session.setAttribute("previousID_NUM", previousID_NUM);
            
         	
            @SuppressWarnings("unchecked")
                  List<String> previousADDITIONALINFO =
                  (List<String>)session.getAttribute("previousADDITIONALINFO");
               
            if (previousADDITIONALINFO== null) {
               previousADDITIONALINFO = new ArrayList<String>();
            }
            String ADDITIONALINFO= request.getParameter("ADDITIONALINFO");
            if ((ADDITIONALINFO != null) &&
               (!ADDITIONALINFO.trim().equals(""))) {
               previousADDITIONALINFO.add(ADDITIONALINFO);
            }
            session.setAttribute("previousADDITIONALINFO", previousADDITIONALINFO);
            
         	
            @SuppressWarnings("unchecked")
                  List<String> previousADDITIONALINFO2 =
                  (List<String>)session.getAttribute("previousADDITIONALINFO2");
               
            if (previousADDITIONALINFO2== null) {
               previousADDITIONALINFO2 = new ArrayList<String>();
            }
            String ADDITIONALINFO2= request.getParameter("ADDITIONALINFO2");
            if ((ADDITIONALINFO2 != null) &&
               (!ADDITIONALINFO2.trim().equals(""))) {
               previousADDITIONALINFO2.add(ADDITIONALINFO2);
            }
            session.setAttribute("previousADDITIONALINFO2", previousADDITIONALINFO2);
            
         	
            @SuppressWarnings("unchecked")
                  List<String> previousQUANTITY =
                  (List<String>)session.getAttribute("previousQUANTITY");
               
            if (previousQUANTITY== null) {
               previousQUANTITY = new ArrayList<String>();
            }
            String QUANTITY= request.getParameter("QUANTITY");
            if ((QUANTITY != null) &&
               (!QUANTITY.trim().equals(""))) {
               previousQUANTITY.add(QUANTITY);
            }
            session.setAttribute("previousQUANTITY", previousQUANTITY);
            
         	
            @SuppressWarnings("unchecked")
                  List<String> previousPRICE =
                  (List<String>)session.getAttribute("previousPRICE");
               
            if (previousPRICE== null) {
               previousPRICE = new ArrayList<String>();
            }
            String PRICE= request.getParameter("PRICE");
            if ((PRICE != null) &&
               (!PRICE.trim().equals(""))) {
               previousPRICE.add(PRICE);
            }
            session.setAttribute("previousPRICE", previousPRICE);
            
         	
            @SuppressWarnings("unchecked")
                  List<String> previousSHIPPING =
                  (List<String>)session.getAttribute("previousSHIPPING");
               
            if (previousSHIPPING== null) {
               previousSHIPPING = new ArrayList<String>();
            }
            String SHIPPING= request.getParameter("SHIPPING");
            if ((SHIPPING != null) &&
               (!SHIPPING.trim().equals(""))) {
               previousSHIPPING.add(SHIPPING);
            }
            session.setAttribute("previousSHIPPING", previousSHIPPING);
            
         
            String price = request.getParameter("PRICE");
            double cost = Double.parseDouble(price);
            String quantity = request.getParameter("QUANTITY");
            int count = Integer.parseInt(quantity);
            String shipping = request.getParameter("SHIPPING");
            double delivery = Double.parseDouble(shipping);
            double total = (count * cost + delivery);
            int r = (int)(total * 100);
            double Total = r / 100.0;
            
         	
            String firstName = (String) session.getAttribute("firstname");
            String lastName = (String) session.getAttribute("lastname");
            
         	
            response.setContentType("text/html");
         
            PrintWriter writer = response.getWriter();		
         
            writer.write("<html>");
            writer.write("<head>");
            writer.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"../../../shoppe/css/centerElementCheckout.css\" />");
            writer.write("<title>D N D Shoppe</title>");
            writer.write("</head>");
            writer.write("<body background=\"../../../shoppe/photos/green-abstract-background.jpg\">");
            writer.write("<center>");
            writer.write("<a><img src=\"../../../shoppe/photos/logo.png\" width=\"700\" height=\"300\" border=\"0\" alt=\"D N D\"></a>");
            writer.write("</center>");
            writer.write("<div id=\"horizon\">");
            writer.write("<div id=\"content\">");
         
         //Shopping cart starts here
            writer.write("<form onsubmit=\"return (checkForm(this) &amp;&amp; true);\" action=\"ContactServlet\" method=\"POST\">");  
            writer.write("<table width=\"1000px\" border=1 align=\"center\">");
            writer.write("<caption><h1>" + firstName + " " + lastName + "'s Shopping Cart</h1></caption>");
            writer.write("<TR><TD width=\"125px\">Item Name: </TD>");
            writer.write("<TD width=\"125px\">Item # </TD>");
            writer.write("<TD width=\"125px\">Color: </TD>");
            writer.write("<TD width=\"125px\">Size: </TD>");
            writer.write("<TD width=\"125px\">Quantity: </TD>");
            writer.write("<TD width=\"125px\">Price: </TD>");
            writer.write("<TD width=\"125px\">Shipping: </TD>");
            writer.write("<TD width=\"125px\">Subtotal: </TD>");
            writer.write("<TR>");
            
            for(String item: previousNAME) {
               addTableColumn(writer, item); 
            }
         
            for(String itemNUM: previousID_NUM) {
               writer.write("<TD>" + itemNUM + "</TD>");
            }
         
            for(String itemCOLOR: previousADDITIONALINFO) {
               writer.write("<TD>" + itemCOLOR + "</TD>");
            }
         
            for(String itemSIZE: previousADDITIONALINFO2) {
               writer.write("<TD>" + itemSIZE + "</TD>");
            }
         
            for(String itemCOUNT: previousQUANTITY) {
               writer.write("<TD>" + itemCOUNT + "</TD>");
            }
         
            for(String itemCOST: previousPRICE) {
               writer.write("<TD>" + itemCOST + "</TD>");
            }
         
            for(String itemSEND: previousSHIPPING) {
               writer.write("<TD>" + itemSEND + "</TD>");
            }
         	
         
            writer.write("<tr><td align=center COLSPAN=\"2\"><input type=\"submit\" name=\"Submit\" value=\"Place Your Order\"></td>");
            writer.write("<FORM METHOD=\"LINK\" ACTION=\"STUBBBB\"><td align=center COLSPAN=\"2\"><input type=\"button\" value=\"Continue Shopping\"onclick=\"javascript: history.go(-1)\"></td></FORM>");  
            writer.write("<FORM METHOD=\"LINK\" ACTION=\"LoginServlet\"><td align=center COLSPAN=\"2\"><INPUT TYPE=\"submit\" VALUE=\"Exit Now\"></td></FORM>");
            writer.write("<td align=center COLSPAN=\"2\" ><B><I>" + "Total: $" + Total + "</I></B></td></tr>");
            writer.write("</table>");
            writer.write("</form>");
         
            writer.write("</center>");
            writer.write("</body>");
            writer.write("</html>");
            writer.close();
         }
      }
      private static void startTableRow(PrintWriter writer) {
         writer.write("<tr>");	
      }
   
      private static void closeTableRow(PrintWriter writer) {
         writer.write("</tr>");	
      }
   
      private static void addTableColumn(PrintWriter writer, String value) {
         writer.write("<td> "+ value + "</td>");	
      }
   
   }


Thank you so mush for your help. You have a great way of explaining this complicated subject.

This post has been edited by macosxnerd101: 11 February 2012 - 11:47 AM
Reason for edit:: Removed long quote

Was This Post Helpful? 0
  • +
  • -

#7 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7293
  • View blog
  • Posts: 12,114
  • Joined: 19-March 11

Re: Displaying a table correctly?

Posted 11 February 2012 - 12:09 AM

The examples with Tables and Cells and Rows and stuff would require that you generate the code to define those classes. They're not existing classes (well, maybe someone's written them, but I don't know about them). So that's why they didn't compile: the classes don't exist.

A naive implementation would be not be hard, a good one would be some work, and a really good one might be very difficult indeed. Let's look at the naive one:

A Cell, in this very simple case, just has some text, so you need a constructor which accepts a String, and it has a single method, which just returns the text, wrapped in <td> tags. Dead simple. You could complicate it: you could allow the user to change the text, you might want to allow for attributes, stuff like that. You could also go completely over the top, but we won't go there tonight.
A Row would have a list of Cells. You'd want to have an add() method which would take a Cell as its argument, and again you'd like to have a method returning this Row as an HTML string. That method would cat together a String starting with the <tr> tag, then loop through the list of Cells, getting each one's HTML representation, then stick on the </tr> tag, and you're set.
Now a Table is a lot like a Row - you want to be able to add Rows, and to return the HTML, which is assembled the same way as you'd do for the Table.
Row and Table would probably do nicely with attributes and some other methods. Playing with the simple version will make you wish for features. Since it's your class, you can add them if you want - that's the beauty of code.

Simplest thing to do would be to stick with the first example I gave, which shouldn't be hard to incorporate into your code.
Was This Post Helpful? 1
  • +
  • -

#8 Java Neil  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 140
  • Joined: 26-March 11

Re: Displaying a table correctly?

Posted 11 February 2012 - 12:14 AM

Sorry, but this is all a bit over my head. I wrote this code by using examples from a java book I have here at the house. I still learning a lot of basics.
Was This Post Helpful? 0
  • +
  • -

#9 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7293
  • View blog
  • Posts: 12,114
  • Joined: 19-March 11

Re: Displaying a table correctly?

Posted 11 February 2012 - 12:36 AM

Take this example:
StringBuilder sb = new StringBuilder();

for (int i = 0; i < previousName.length; i++)
{
sb.append("<tr>");

   sb.append("<TD>" + previousName[i] + "</TD>");
sb.append("<TD>" + previousID_NUM[i] + "</TD>");

sb.append("<TD>" + previousADDITIONALINFO[i] + "</TD>");
sb.append("<TD>" + previousADDITIONALINFO2[i] + "</TD>");
sb.append("<TD>" + previousQUANTITY[i] + "</TD>");
sb.append("<TD>" + previousPRICE[i] + "</TD>");
sb.append("<TD>" + previousSHIPPING[i] + "</TD>");
sb.append("</tr> \n");  // newline added for a bit of readability

writer.write(sb.toString()); // you could do this outside the loop as well
}


I'm assuming that your data is represented as arrays. This may be incorrect on my part. If you're using lists, you'd use previousName.get(i) in place of previousName[i]. Beyond that, you should be able to work with that.

If you're not up to writing classes yet, put the other stuff aside for now. It'll probably be worth your time to read it over a few times and try to glean what you can from it, but don't kill yourself over it - that stuff will come soon enough.
Was This Post Helpful? 1
  • +
  • -

#10 Java Neil  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 140
  • Joined: 26-March 11

Re: Displaying a table correctly?

Posted 11 February 2012 - 12:50 AM

View Postjon.kiparsky, on 11 February 2012 - 12:36 AM, said:

I'm assuming that your data is represented as arrays. This may be incorrect on my part. If you're using lists, you'd use previousName.get(i) in place of previousName[i].


Here is my code so you may better see what I need to accomplish and what type of problem I'm having.

   import java.io.IOException;
   import java.io.PrintWriter;
   import java.util.Arrays;  
   import java.util.List;  
   import java.util.ArrayList;
   import javax.servlet.ServletException;
   import javax.servlet.http.HttpServlet;
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
   import javax.servlet.http.HttpSession;
 
   public class CartServlet extends HttpServlet {
   
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      
         HttpSession session = request.getSession();
         
         synchronized(session) {
            @SuppressWarnings("unchecked")
                  List<String> previousNAME =
                  (List<String>)session.getAttribute("previousNAME");
               
            if (previousNAME== null) {
               previousNAME = new ArrayList<String>();
            }
            String NAME= request.getParameter("NAME");
            if ((NAME != null) &&
               (!NAME.trim().equals(""))) {
               previousNAME.add(NAME);
            }
            session.setAttribute("previousNAME", previousNAME);
            
            
            @SuppressWarnings("unchecked")
                  List<String> previousID_NUM =
                  (List<String>)session.getAttribute("previousID_NUM");
               
            if (previousID_NUM== null) {
               previousID_NUM = new ArrayList<String>();
            }
            String ID_NUM= request.getParameter("ID_NUM");
            if ((ID_NUM != null) &&
               (!ID_NUM.trim().equals(""))) {
               previousID_NUM.add(ID_NUM);
            }
            session.setAttribute("previousID_NUM", previousID_NUM);
            
         	
            @SuppressWarnings("unchecked")
                  List<String> previousADDITIONALINFO =
                  (List<String>)session.getAttribute("previousADDITIONALINFO");
               
            if (previousADDITIONALINFO== null) {
               previousADDITIONALINFO = new ArrayList<String>();
            }
            String ADDITIONALINFO= request.getParameter("ADDITIONALINFO");
            if ((ADDITIONALINFO != null) &&
               (!ADDITIONALINFO.trim().equals(""))) {
               previousADDITIONALINFO.add(ADDITIONALINFO);
            }
            session.setAttribute("previousADDITIONALINFO", previousADDITIONALINFO);
            
         	
            @SuppressWarnings("unchecked")
                  List<String> previousADDITIONALINFO2 =
                  (List<String>)session.getAttribute("previousADDITIONALINFO2");
               
            if (previousADDITIONALINFO2== null) {
               previousADDITIONALINFO2 = new ArrayList<String>();
            }
            String ADDITIONALINFO2= request.getParameter("ADDITIONALINFO2");
            if ((ADDITIONALINFO2 != null) &&
               (!ADDITIONALINFO2.trim().equals(""))) {
               previousADDITIONALINFO2.add(ADDITIONALINFO2);
            }
            session.setAttribute("previousADDITIONALINFO2", previousADDITIONALINFO2);
            
         	
            @SuppressWarnings("unchecked")
                  List<String> previousQUANTITY =
                  (List<String>)session.getAttribute("previousQUANTITY");
               
            if (previousQUANTITY== null) {
               previousQUANTITY = new ArrayList<String>();
            }
            String QUANTITY= request.getParameter("QUANTITY");
            if ((QUANTITY != null) &&
               (!QUANTITY.trim().equals(""))) {
               previousQUANTITY.add(QUANTITY);
            }
            session.setAttribute("previousQUANTITY", previousQUANTITY);
            
         	
            @SuppressWarnings("unchecked")
                  List<String> previousPRICE =
                  (List<String>)session.getAttribute("previousPRICE");
               
            if (previousPRICE== null) {
               previousPRICE = new ArrayList<String>();
            }
            String PRICE= request.getParameter("PRICE");
            if ((PRICE != null) &&
               (!PRICE.trim().equals(""))) {
               previousPRICE.add(PRICE);
            }
            session.setAttribute("previousPRICE", previousPRICE);
            
         	
            @SuppressWarnings("unchecked")
                  List<String> previousSHIPPING =
                  (List<String>)session.getAttribute("previousSHIPPING");
               
            if (previousSHIPPING== null) {
               previousSHIPPING = new ArrayList<String>();
            }
            String SHIPPING= request.getParameter("SHIPPING");
            if ((SHIPPING != null) &&
               (!SHIPPING.trim().equals(""))) {
               previousSHIPPING.add(SHIPPING);
            }
            session.setAttribute("previousSHIPPING", previousSHIPPING);
            
         
            String price = request.getParameter("PRICE");
            double cost = Double.parseDouble(price);
            String quantity = request.getParameter("QUANTITY");
            int count = Integer.parseInt(quantity);
            String shipping = request.getParameter("SHIPPING");
            double delivery = Double.parseDouble(shipping);
            double total = (count * cost + delivery);
            int r = (int)(total * 100);
            double Total = r / 100.0;
            
         	
            String firstName = (String) session.getAttribute("firstname");
            String lastName = (String) session.getAttribute("lastname");
            
         	
            response.setContentType("text/html");
         
            PrintWriter writer = response.getWriter();		
         
            writer.write("<html>");
            writer.write("<head>");
            writer.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"../../../shoppe/css/centerElementCheckout.css\" />");
            writer.write("<title>D N D Shoppe</title>");
            writer.write("</head>");
            writer.write("<body background=\"../../../shoppe/photos/green-abstract-background.jpg\">");
            writer.write("<center>");
            writer.write("<a><img src=\"../../../shoppe/photos/logo.png\" width=\"700\" height=\"300\" border=\"0\" alt=\"D N D\"></a>");
            writer.write("</center>");
            writer.write("<div id=\"horizon\">");
            writer.write("<div id=\"content\">");
         
         //Shopping cart starts here
            writer.write("<form onsubmit=\"return (checkForm(this) &amp;&amp; true);\" action=\"ContactServlet\" method=\"POST\">");  
            writer.write("<table width=\"1000px\" border=1 align=\"center\">");
            writer.write("<caption><h1>" + firstName + " " + lastName + "'s Shopping Cart</h1></caption>");
            writer.write("<TR><TD width=\"125px\">Item Name: </TD>");
            writer.write("<TD width=\"125px\">Item # </TD>");
            writer.write("<TD width=\"125px\">Color: </TD>");
            writer.write("<TD width=\"125px\">Size: </TD>");
            writer.write("<TD width=\"125px\">Quantity: </TD>");
            writer.write("<TD width=\"125px\">Price: </TD>");
            writer.write("<TD width=\"125px\">Shipping: </TD>");
            writer.write("<TD width=\"125px\">Subtotal: </TD>");
            writer.write("<TR>");
            
            for(String item: previousNAME) {
               writer.write("<TD>" + item + "</TD>");
            }
         
            for(String itemNUM: previousID_NUM) {
               writer.write("<TD>" + itemNUM + "</TD>");
            }
         
            for(String itemCOLOR: previousADDITIONALINFO) {
               writer.write("<TD>" + itemCOLOR + "</TD>");
            }
         
            for(String itemSIZE: previousADDITIONALINFO2) {
               writer.write("<TD>" + itemSIZE + "</TD>");
            }
         
            for(String itemCOUNT: previousQUANTITY) {
               writer.write("<TD>" + itemCOUNT + "</TD>");
            }
         
            for(String itemCOST: previousPRICE) {
               writer.write("<TD>" + itemCOST + "</TD>");
            }
         
            for(String itemSEND: previousSHIPPING) {
               writer.write("<TD>" + itemSEND + "</TD>");
            }
         	
         
            writer.write("<tr><td align=center COLSPAN=\"2\"><input type=\"submit\" name=\"Submit\" value=\"Place Your Order\"></td>");
            writer.write("<FORM METHOD=\"LINK\" ACTION=\"STUBBBB\"><td align=center COLSPAN=\"2\"><input type=\"button\" value=\"Continue Shopping\"onclick=\"javascript: history.go(-1)\"></td></FORM>");  
            writer.write("<FORM METHOD=\"LINK\" ACTION=\"LoginServlet\"><td align=center COLSPAN=\"2\"><INPUT TYPE=\"submit\" VALUE=\"Exit Now\"></td></FORM>");
            writer.write("<td align=center COLSPAN=\"2\" ><B><I>" + "Total: $" + Total + "</I></B></td></tr>");
            writer.write("</table>");
            writer.write("</form>");
         
            writer.write("</center>");
            writer.write("</body>");
            writer.write("</html>");
            writer.close();
         }
      }
      private static void startTableRow(PrintWriter writer) {
         writer.write("<tr>");	
      }
   
      private static void closeTableRow(PrintWriter writer) {
         writer.write("</tr>");	
      }
   
      private static void addTableColumn(PrintWriter writer, String value) {
         writer.write("<td> "+ value + "</td>");	
      }
   
   }

Was This Post Helpful? 0
  • +
  • -

#11 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1131
  • View blog
  • Posts: 2,484
  • Joined: 05-May 05

Re: Displaying a table correctly?

Posted 11 February 2012 - 01:24 AM

for(String item: previousNAME) {
   writer.write("<TR><TD>" + item + "</TD>");
}



Your use of HTML is wrong. In that for you create as many rows as there is items, when you should be creating one row and multiple data cells (columns). Luckily, you only have a few items to display, so it doesn't like that abnormal. If you had more it would look really weird.

writer.write("<TR>");
for(String item: previousNAME) {
   writer.write("<TD>" + item + "</TD>");
}
writer.write("</TR>");



Make all your loops look like that and your table will come out correctly.

Just wondering, but why are you synchronizing on the session variable? The whole point of having a session to create on-going conversion between a client and server. Each HttpServletRequest, and its session, is unique to the client. You don't have to worry about thread-safety.

This post has been edited by blackcompe: 11 February 2012 - 05:27 AM

Was This Post Helpful? 0
  • +
  • -

#12 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1131
  • View blog
  • Posts: 2,484
  • Joined: 05-May 05

Re: Displaying a table correctly?

Posted 11 February 2012 - 05:53 AM

It appears that the first half of your code is retrieving the new user item entered through a form. Although there are more elegant ways to do this, what you have works. You can make your code a lot more readable by separating it into functions, renaming variables, and getting rid of redundant code.

1. Rename your variables to something more intuitive. Use the search/replace function in your editor. :^: A simple replacement, suddenly makes your code much easier to read and to figure out what's happening.

         @SuppressWarnings("unchecked")
         List<String> itemNameList = (List<String>)
         session.getAttribute("itemNameList");   
         
         if (itemNameList== null) {
            itemNameList = new ArrayList<String>();
         }
         
         String itemName= request.getParameter("itemName");
         if ((itemName != null) 
         && (!itemName.trim().equals(""))) {
            itemNameList.add(itemName);
         }



2. Get rid of redundant code:

session.setAttribute("previousNAME", previousNAME);



setAttribute returns a reference to your list. When you alter it, the changes are reflected when you go to get the list from the session again, since the session only holds a reference to it. I'm pretty sure that resetting the attribute is unnecessary, and if it is, your cart will fail to update.

3. Try to keep your methods small:

private void updateNameList(HttpServletRequest req) { 
              @SuppressWarnings("unchecked")
              List<String> itemNameList = (List<String>)session.getAttribute("itemNameList");   
              if (itemNameList== null) {
                  itemNameList = new ArrayList<String>();
              }
              
              String itemName= request.getParameter("itemName");
              if ((itemName != null) && (!itemName.trim().equals(""))) {
                  itemNameList.add(itemName);
              }
              session.setAttribute("itemNameList", itemNameList);
}



then your doGet becomes:

synchronized(session) {
          
          updateNameList(req);
          updateIDList(req);
          updateAdditionalInfoList(req);



Do the same with all the HTML output.
Was This Post Helpful? 0
  • +
  • -

#13 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5643
  • View blog
  • Posts: 12,359
  • Joined: 16-October 07

Re: Displaying a table correctly?

Posted 11 February 2012 - 06:29 AM

Odd, you have addTableColumn but don't use it. There's no conceivable reason why it should be static, either. If you had some more methods...

private void addTableColumn(PrintWriter writer, String value) {
	writer.write("<td> "+ value + "</td>");	
}

private void addTableColumn(PrintWriter writer, Iterable<String> values) {
	for(String item : values) {
		addTableColumn(value);
	}
}



You could actually use them in that block of loops:
addTableColumn(previousNAME);
addTableColumn(previousID_NUM);
addTableColumn(previousADDITIONALINFO);
addTableColumn(previousADDITIONALINFO2);
addTableColumn(previousQUANTITY);
addTableColumn(previousPRICE);
addTableColumn(previousSHIPPING);



You have a whole lot of copy past code here. You could probably use some methods for how you grab all those lists. e.g
List<String> previousNAME = getInfoAddPrev(request, session, "previousNAME", "NAME");
List<String> previousID_NUM = getInfoAddPrev(request, session, "previousID_NUM", "ID_NUM");



Hope this helps.

This post has been edited by baavgai: 11 February 2012 - 06:30 AM

Was This Post Helpful? 1
  • +
  • -

#14 Java Neil  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 140
  • Joined: 26-March 11

Re: Displaying a table correctly?

Posted 11 February 2012 - 11:29 AM

View Postblackcompe, on 11 February 2012 - 05:53 AM, said:

then your doGet becomes:

synchronized(session) {
          
          updateNameList(req);
          updateIDList(req);
          updateAdditionalInfoList(req);



Do the same with all the HTML output.


Ok, I see the importance of keeping it all clean and compartmentalized. Here is the updated code trying to follow your instructions. I am confused by what you mean by "Do the same with all the HTML output" part? Also how should I call the methods into the for loops? I just want to do this correctly.

   import java.io.IOException;
   import java.io.PrintWriter;
   import java.util.Arrays;  
   import java.util.List;  
   import java.util.ArrayList;
   import javax.servlet.ServletException;
   import javax.servlet.http.HttpServlet;
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
   import javax.servlet.http.HttpSession;
 
   public class CartServlet extends HttpServlet {
   
   //The name of the product
      private void updateNameList(HttpServletRequest request) { 
      
         HttpSession session = request.getSession();
         
         @SuppressWarnings("unchecked")
              List<String> itemNameList = (List<String>)session.getAttribute("itemNameList");   
         if (itemNameList== null) {
            itemNameList = new ArrayList<String>();
         }
              
         String itemName= request.getParameter("itemName");
         if ((itemName != null) && (!itemName.trim().equals(""))) {
            itemNameList.add(itemName);
         }
         session.setAttribute("itemNameList", itemNameList);
      }
      
   //The ID of the product
      private void updateIDList(HttpServletRequest request) { 
      
         HttpSession session = request.getSession();
         
         @SuppressWarnings("unchecked")
                  List<String> itemIDList =
                  (List<String>)session.getAttribute("itemIDList");
               
         if (itemIDList== null) {
            itemIDList= new ArrayList<String>();
         }
         String itemID= request.getParameter("itemID");
         if ((itemID != null) &&
               (!itemID.trim().equals(""))) {
            itemIDList.add(itemID);
         }
         session.setAttribute("itemIDList", itemIDList);
      }
      
   //The color of the product
      private void updateColorList(HttpServletRequest request) { 
      
         HttpSession session = request.getSession();
         
         @SuppressWarnings("unchecked")
                  List<String> itemColorList =
                  (List<String>)session.getAttribute("itemColorList");
               
         if (itemColorList== null) {
            itemColorList= new ArrayList<String>();
         }
         String itemColor= request.getParameter("itemColor");
         if ((itemColor != null) &&
               (!itemColor.trim().equals(""))) {
            itemColorList.add(itemColor);
         }
         session.setAttribute("itemColorList", itemColorList);
      }
      
   //The size of the product
      private void updateSizeList(HttpServletRequest request) { 
      
         HttpSession session = request.getSession();
         
         @SuppressWarnings("unchecked")
                  List<String> itemSizeList =
                  (List<String>)session.getAttribute("itemSizeList");
               
         if (itemSizeList== null) {
            itemSizeList= new ArrayList<String>();
         }
         String itemSize= request.getParameter("itemSize");
         if ((itemSize != null) &&
               (!itemSize.trim().equals(""))) {
            itemSizeList.add(itemSize);
         }
         session.setAttribute("itemSizeList", itemSizeList);
      }
      
   //The quantity of the product
      private void updateQuantityList(HttpServletRequest request) { 
      
         HttpSession session = request.getSession();
         
         @SuppressWarnings("unchecked")
                  List<String> itemQuantityList =
                  (List<String>)session.getAttribute("itemQuantityList");
               
         if (itemQuantityList== null) {
            itemQuantityList= new ArrayList<String>();
         }
         String itemQuantity= request.getParameter("itemQuantity");
         if ((itemQuantity != null) &&
               (!itemQuantity.trim().equals(""))) {
            itemQuantityList.add(itemQuantity);
         }
         session.setAttribute("itemQuantityList", itemQuantityList);
      }	
      
   //The price of the product
      private void updatePriceList(HttpServletRequest request) { 
      
         HttpSession session = request.getSession();
         
         @SuppressWarnings("unchecked")
                  List<String> itemPriceList =
                  (List<String>)session.getAttribute("itemPriceList");
               
         if (itemPriceList== null) {
            itemPriceList= new ArrayList<String>();
         }
         String itemPrice= request.getParameter("itemPrice");
         if ((itemPrice != null) &&
               (!itemPrice.trim().equals(""))) {
            itemPriceList.add(itemPrice);
         }
         session.setAttribute("itemPriceList", itemPriceList);
      }
      
   //The shipping cost of the product
      private void updateShippingList(HttpServletRequest request) { 
      
         HttpSession session = request.getSession();
         
         @SuppressWarnings("unchecked")
                  List<String> itemShippingList =
                  (List<String>)session.getAttribute("itemShippingList");
               
         if (itemShippingList== null) {
            itemShippingList= new ArrayList<String>();
         }
         String itemShipping= request.getParameter("itemShipping");
         if ((itemShipping != null) &&
               (!itemShipping.trim().equals(""))) {
            itemShippingList.add(itemShipping);
         }
         session.setAttribute("itemShippingList", itemShippingList);
      }
   
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      
         HttpSession session = request.getSession();
         
         synchronized(session) {
          
            updateNameList(request);
            updateIDList(request); 
            updateColorList(request);
            updateSizeList(request);
            updateQuantityList(request);   
            updatePriceList(request);
            updateShippingList(request); 
         	  
         
            String price = request.getParameter("itemPrice");
            double cost = Double.parseDouble(price);
            String quantity = request.getParameter("itemQuantity");
            int count = Integer.parseInt(quantity);
            String shipping = request.getParameter("itemShipping");
            double delivery = Double.parseDouble(shipping);
            double total = (count * cost + delivery);
            int r = (int)(total * 100);
            double Total = r / 100.0;
            
         	
            String firstName = (String) session.getAttribute("firstname");
            String lastName = (String) session.getAttribute("lastname");
            
         	
            response.setContentType("text/html");
         
            PrintWriter writer = response.getWriter();		
         
            writer.write("<html>");
            writer.write("<head>");
            writer.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"../../../shoppe/css/centerElementCheckout.css\" />");
            writer.write("<title>D N D Shoppe</title>");
            writer.write("</head>");
            writer.write("<body background=\"../../../shoppe/photos/green-abstract-background.jpg\">");
            writer.write("<center>");
            writer.write("<a><img src=\"../../../shoppe/photos/logo.png\" width=\"700\" height=\"300\" border=\"0\" alt=\"D N D\"></a>");
            writer.write("</center>");
            writer.write("<div id=\"horizon\">");
            writer.write("<div id=\"content\">");
         
         //Shopping cart starts here
            writer.write("<form onsubmit=\"return (checkForm(this) &amp;&amp; true);\" action=\"ContactServlet\" method=\"POST\">");  
            writer.write("<table width=\"1000px\" border=1 align=\"center\">");
            writer.write("<caption><h1>" + firstName + " " + lastName + "'s Shopping Cart</h1></caption>");
            writer.write("<TR><TD width=\"125px\">Item Name: </TD>");
            writer.write("<TD width=\"125px\">Item # </TD>");
            writer.write("<TD width=\"125px\">Color: </TD>");
            writer.write("<TD width=\"125px\">Size: </TD>");
            writer.write("<TD width=\"125px\">Quantity: </TD>");
            writer.write("<TD width=\"125px\">Price: </TD>");
            writer.write("<TD width=\"125px\">Shipping: </TD>");
            writer.write("<TD width=\"125px\">Subtotal: </TD>");
         	
            writer.write("<TR>");
            
         	
         //test string (for loops) go here!
         

            writer.write("</TR>");
         	
         
            writer.write("<tr><td align=center COLSPAN=\"2\"><input type=\"submit\" name=\"Submit\" value=\"Place Your Order\"></td>");
            writer.write("<FORM METHOD=\"LINK\" ACTION=\"STUBBBB\"><td align=center COLSPAN=\"2\"><input type=\"button\" value=\"Continue Shopping\"onclick=\"javascript: history.go(-1)\"></td></FORM>");  
            writer.write("<FORM METHOD=\"LINK\" ACTION=\"LoginServlet\"><td align=center COLSPAN=\"2\"><INPUT TYPE=\"submit\" VALUE=\"Exit Now\"></td></FORM>");
            writer.write("<td align=center COLSPAN=\"2\" >" + "Total: $" + Total + "</td></tr>");
            writer.write("</table>");
            writer.write("</form>");
         
            writer.write("</center>");
            writer.write("</body>");
            writer.write("</html>");
            writer.close();
         
         }
      }
      private static void startTableRow(PrintWriter writer) {
         writer.write("<tr>");	
      }
   
      private static void closeTableRow(PrintWriter writer) {
         writer.write("</tr>");	
      }
   
      private static void addTableColumn(PrintWriter writer, String value) {
         writer.write("<td> "+ value + "</td>");	
      }
   
   }


I hope this is going in the proper direction!

View Postbaavgai, on 11 February 2012 - 06:29 AM, said:

Odd, you have addTableColumn but don't use it. There's no conceivable reason why it should be static, either. If you had some more methods...

private void addTableColumn(PrintWriter writer, String value) {
	writer.write("<td> "+ value + "</td>");	
}

private void addTableColumn(PrintWriter writer, Iterable<String> values) {
	for(String item : values) {
		addTableColumn(value);
	}
}



You could actually use them in that block of loops:
addTableColumn(previousNAME);
addTableColumn(previousID_NUM);
addTableColumn(previousADDITIONALINFO);
addTableColumn(previousADDITIONALINFO2);
addTableColumn(previousQUANTITY);
addTableColumn(previousPRICE);
addTableColumn(previousSHIPPING);



You have a whole lot of copy past code here. You could probably use some methods for how you grab all those lists. e.g
List<String> previousNAME = getInfoAddPrev(request, session, "previousNAME", "NAME");
List<String> previousID_NUM = getInfoAddPrev(request, session, "previousID_NUM", "ID_NUM");



Hope this helps.



I get an error stating ...

CartServlet.java:248: cannot find symbol
symbol : variable value
location: class CartServlet
addTableColumn(value);
^
1 error

This post has been edited by Java Neil: 11 February 2012 - 11:28 AM

Was This Post Helpful? 0
  • +
  • -

#15 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10183
  • View blog
  • Posts: 37,596
  • Joined: 27-December 08

Re: Displaying a table correctly?

Posted 11 February 2012 - 11:47 AM

Moved to Java EE, since you are dealing with Servlets.

Also, I merged this with your previous thread. Please don't duplicate post.
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3