?
Solved

generate a dynamic table on JSP page

Posted on 2009-04-03
6
Medium Priority
?
797 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 5

Accepted Solution

by:
TheVeee earned 1500 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
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 1500 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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.
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

801 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