Solved

generate a dynamic table on JSP page

Posted on 2009-04-03
6
740 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mergeTwo  challenge 13 71
Tools or ways to handle development of complex web applications 4 73
network + 7 73
strDist challenge 35 84
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now