Solved

generate a dynamic table on JSP page

Posted on 2009-04-03
6
748 Views
Last Modified: 2012-06-27
Hi Experts,
           I am displaying the attached chart on my jsp page, Every new month is added in the X-axis as soon as the month gets populated in the Database Table.
           What I want to achieve is , Display the data (SLA Compliance column of the table) present in the chart in a tabular Form, with Column names as months, and with the addition of a new month, a new column should automatically be generated.
           Can someone please help me out with this.

           I have attached the Chart snap shot along with  a snippet of backend Table, used for this chart
           
Chart.PNG
back-Table.PNG
0
Comment
Question by:aman0711
  • 3
  • 3
6 Comments
 
LVL 5

Accepted Solution

by:
TheVeee earned 500 total points
ID: 24059506
1.  First create a bean with Application, Month, Year, SLA_COMPLIANCE and then Total_Metrics attributes and for example we will call it BeanA.

2.  Next in the servlet create a ArrayList named BeanA_ArrayList.

3.  Next loop thru database resultset and as you read each row from the result set, create a new BeanA.

4.  Once done creating BeanA from step3, then add it to a ArrayList called BeanA_ArrayList.

5.  Then store the ArrayList to the request object.

5.  Once done call your jsp page you want to display your table in.

6.  Next in your jsp add addressibility to the ArrayList from the request object.

7.  Next loop thru the arraylist and build the html on the fly.

Look at the below tutorial then go to booklist.jsp... will show you...
http://www.laliluna.de/first-java-servlets-jsp-tutorial.html
0
 
LVL 10

Author Comment

by:aman0711
ID: 24059547
Hi Vee,
             I am very new to Java.. I never worked with JSP and Servlet. Just know a little about jsp
0
 
LVL 5

Expert Comment

by:TheVeee
ID: 24059604
thats ok, we all hav to learn.. np....
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 10

Author Comment

by:aman0711
ID: 24059653
What I was doing till now is this.
just the scratch..

Its giving me the first column fine as Jul, but all others vertically below it

<table border="1" cellspacing="1" bgcolor="#FFFFFF" WIDTH=99.5%>
	<tr>
		<th>Application</th>
		
 
 
	<%
		Connection conn = null;
		conn = db.getConnection();
 
		String sql = "";
		PreparedStatement pstmt = null;
		ResultSet rs = null;
 
		sql = "Select * from WEB_EXSUMM_12MONTH_APPL_V WHERE APPLICATION='ED' ORDER BY DECODE(UPPER(MONTH), 'JAN', 7, 'FEB', 8, 'MAR', 9, 'APR', 10, 'MAY', 11, 'JUN', 12, 'JUL', 1, 'AUG', 2, 'SEP', 3, 'OCT', 4, 'NOV', 5, 'DEC', 6)";
		pstmt = conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
		rs = pstmt.executeQuery(sql);
		
		while (rs.next()) {
	%>
        <th align='center'><%=rs.getString(2) %></th>
     </tr>   
	<tr>
 
		<td><%=rs.getString(1)%></td>
		
		
	</tr>
 
	<%
		}
		rs.close();
		pstmt.close();
		conn.close();
	%>
 
</table>

Open in new window

0
 
LVL 5

Assisted Solution

by:TheVeee
TheVeee earned 500 total points
ID: 24059661
Heres their example, notice that arraylist books is retrieved from the request object.  The servlet prior to calling the jsp, set the attribute of books with the ArrayList they wanted.

<%                                    ArrayList arrayList = (ArrayList)request.getAttribute("books");                            //loope über die Liste von Büchern und gibt die Eigenschaften aus              for (Iterator iter = arrayList.iterator(); iter.hasNext();) {                    Book element = (Book) iter.next();                                      out.println("<tr>");                  out.println("<td>" + element.getAuthor() + "</td>");                  out.println("<td>" + element.getTitle() + "</td>");                  if(element.isAvailable())                        out.println("<td><input type="checkbox" name="available" value="true" disabled checked></td>");                  else                        out.println("<td><input type="checkbox" name="available" value="true" disabled></td>");                                    out.println("<td><a href="bookEdit?do=edit&id=" + element.getId() + "">Edit</a></td>");                  out.println("<td><a href="bookEdit?do=delete&id=" + element.getId() + "">Delete</a></td>");                  out.println("</tr>");              }        %>
0
 
LVL 10

Author Comment

by:aman0711
ID: 24059712
ok, I will try
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
javap not working 8 44
servlet filter example 37 59
String array comparison 4 32
Is there a simpler dropbox system? 10 18
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

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

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

Join & Ask a Question