• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

Ourput Data into 3 Columns

Hello,

I have the following code.  

                    <% if (partVector != null) { %>

                    <% if (partVector.size() == 0) { %>
                              <i>Sorry, no parts found</i><br>
                            <% } else {
                      for (int j=0; j < partVector.size(); j++) {
                        Part part = (Part)partVector.elementAt(j);
                                if (part.productCount == 1) { %>
                          <a href="wizard.jsp?partner=<%= requestedPartner %>&year=<%= requestedYear %>&make=<%= requestedMake %>&model=<%= requestedModel %>&category=<%= category.id %>&part=<%= URLEncoder.encode(part.description) %>"><%= part.description %></a><br>
                        <% } else { %>
                          <a href="wizard.jsp?partner=<%= requestedPartner %>&year=<%= requestedYear %>&make=<%= requestedMake %>&model=<%= requestedModel %>&category=<%= category.id %>&part=<%= URLEncoder.encode(part.description) %>"><%= part.description %>...</a><br>
                           <% }
                        }
                          }      
                         } %>

This gives me a list of parts, that ranges anywhere from 1 to 50 in one column.  What I want is to be able to show this data in a table in 3 columns.  Can anyone provide the code for me?
0
konrad123
Asked:
konrad123
  • 5
  • 4
1 Solution
 
colr__Commented:
Use the modulo operator. So in your for loop (assuming its all held in an html table):

<table>

for (int j=0; j < partVector.size(); j++) {
if (j%3 == 0)
// print out <tr>

//print ut <td> <% output a colum %> </td>

if (j%3 == 2)
// print out </tr>

</table>

The modulo is the remainder of a division, so you can use this to easily cycle through a loop (such as 3 columns as shown above).

colr__
0
 
konrad123Author Commented:
Can you create the exact code using my above so that I can just paste it into my file?  I never worked with JSP before so it will take me hours to figure this out.
0
 
colr__Commented:
If you increase the points I'll have a bash

colr__
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
colr__Commented:
Try this:

<%
if (partVector != null){
      if (partVector.size() == 0) {
            response.println("<i>Sorry, no parts found</i><br>");
      }
      else {
            response.println("<table>");
            for (int j=0; j < partVector.size(); j++) {
                  if (j%3 == 0)
                        response.println("<tr>");
                  response.println("<td>");
                  Part part = (Part)partVector.elementAt(j);
                  if (part.productCount == 1) { %>
                         <a href="wizard.jsp?partner=<%= requestedPartner %>&year=<%= requestedYear %>&make=<%= requestedMake %>&model=<%= requestedModel %>&category=<%= category.id %>&part=<%= URLEncoder.encode(part.description) %>"><%= part.description %></a><br>
                  <% } else { %>
                        <a href="wizard.jsp?partner=<%= requestedPartner %>&year=<%= requestedYear %>&make=<%= requestedMake %>&model=<%= requestedModel %>&category=<%= category.id %>&part=<%= URLEncoder.encode(part.description) %>"><%= part.description %>...</a><br>
                  <% }
                  response.println("</td>");
                  if (j%3 == 2)
                        response.println("</tr>");
            } // end for
            response.println("</table>");
      }  // end else  
} // end
 %>
0
 
konrad123Author Commented:
How many do you want to get this working in the next hour or two?  Will 300 do it?
0
 
konrad123Author Commented:
Here is the error it creates:

Error: 500
Location: /autopartsway/part3.jsp
Internal Servlet Error:

org.apache.jasper.JasperException: Unable to compile Note: sun.tools.javac.Main has been deprecated.
/var/spool/tomcat3/DEFAULT/autopartsway/part3_21.java:195: Method println(java.lang.String) not found in interface javax.servlet.http.HttpServletResponse.
                            response.println("Sorry, no parts found");
                                            ^
/var/spool/tomcat3/DEFAULT/autopartsway/part3_21.java:198: Method println(java.lang.String) not found in interface javax.servlet.http.HttpServletResponse.
                            response.println("");
                                            ^
/var/spool/tomcat3/DEFAULT/autopartsway/part3_21.java:201: Method println(java.lang.String) not found in interface javax.servlet.http.HttpServletResponse.
                                      response.println(" ");
                                                      ^
/var/spool/tomcat3/DEFAULT/autopartsway/part3_21.java:202: Method println(java.lang.String) not found in interface javax.servlet.http.HttpServletResponse.
                                 response.println(" "); ^ /var/spool/tomcat3/DEFAULT/autopartsway/part3_21.java:317: Method println(java.lang.String) not found in interface javax.servlet.http.HttpServletResponse. response.println(" ");
                                                 ^
/var/spool/tomcat3/DEFAULT/autopartsway/part3_21.java:319: Method println(java.lang.String) not found in interface javax.servlet.http.HttpServletResponse.
                                      response.println(" ");
                                                      ^
/var/spool/tomcat3/DEFAULT/autopartsway/part3_21.java:321: Method println(java.lang.String) not found in interface javax.servlet.http.HttpServletResponse.
                            response.println(" ");
                                            ^
Note: /var/spool/tomcat3/DEFAULT/autopartsway/part3_21.java uses or overrides a deprecated API.  Recompile with "-deprecation" for details.
7 errors, 2 warnings

      at org.apache.tomcat.facade.JasperLiaison.javac(JspInterceptor.java)
      at org.apache.tomcat.facade.JasperLiaison.processJspFile(JspInterceptor.java)
      at org.apache.tomcat.facade.JspInterceptor.requestMap(JspInterceptor.java)
      at org.apache.tomcat.core.ContextManager.processRequest(ContextManager.java)
      at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java)
      at org.apache.tomcat.core.ContextManager.service(ContextManager.java)
      at org.apache.tomcat.modules.server.Ajp13Interceptor.processConnection(Ajp13Interceptor.java)
      at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java)
      at java.lang.Thread.run(Thread.java:536)
0
 
colr__Commented:
Replace each instance of response.println with out.println.

colr__
0
 
konrad123Author Commented:
thanks, it works great.  what is your area of expertise?  I may have a lot more of these simple JSP problems.
0
 
colr__Commented:
Java and JSP.
Glad to help ;-)

colr__
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now