Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6834291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:05:37+00:00 2026-05-26T23:05:37+00:00

I’m very new to web development, so bear with me =) Ok here is

  • 0

I’m very new to web development, so bear with me =)

Ok here is my tech stack I’m working with
SQL Server 2008 R2,
Tomcat Server 6.0,
Java 1.6,
jQuery,

Here is my problem.

I have a bunch of report type queries I need to run, and I need to display those results as a table on a JSP page for the user to see. The problem I am running into is the method of how to do this.

Most online examples show to store the results of the query in a ResultSet, and putting it into an ArrayList with JavaBeans setters/getters, and then calling that Arraylist in the JSP.

Another problem is, all these queries have different column headers, and these examples do not show how to dynamically create the column headings (most examples are hardcoded).

Here is an example of what I can do so far to generate a report:

    //inside the servlet and sets stuff inside a JavaBean
public List<ClaimInfoBean> getClaimInfo() throws SQLException {
    List<ClaimInfoBean> claimList = new ArrayList<ClaimInfoBean>();
    while (results.next()) {
        ClaimInfoBean claim = new ClaimInfoBean();
        claim.setClaimNum(results.getString(1));
                    //set more stuff for the bean
        }

        claimList.add(claim);

    }

On the JSP page

        //scriptlet (I know this isnt the best way, but only relevant example I can find)
        List<ClaimInfoBean> claimList = claimData.getClaimInfo();
        Iterator<ClaimInfoBean> claimListIterator = claimList.iterator();
        ClaimInfoBean claim;
        while ( claimListIterator.hasNext() ) {
           claim = ( ClaimInfoBean ) claimListIterator.next();
        //call getXXX to plug into a table

For this servlet, all I care about is running x query, to display y table, when a user clicks a link. This servlet should take any query and display any kind of table, so the way I shown above is very restrictive.

Any help in the right direction would be appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:05:37+00:00Added an answer on May 26, 2026 at 11:05 pm

    Here is the guts of a simple Servlet. getConnection returns a connection to your database, and buildDBRequest returns a PreparedStatement that is set up to execute an SQL query. Both are left as exercises for the reader to implement.

    The key driver for this is the JSTL. In the JSP, JSTL is used to iterate and present the data. One of the interfaces in JSTL is the javax.servlet.jsp.jstl.sql.Result interface. It is normally created by the JSTL SQL tags, which nobody uses (they they’re quite interesting and really flexible — for quick and dirty stuff they work pretty well).

    JSTL also provides a ResultSupport class that conveniently converts a JDBC ResultSet in to a compliant JSTL Result object. So, all the Servlet really needs to do in this case is link up a result set to a JSTL Result, and then forwards to the JSP. Note, when it creates the Result object, it will load in all of the rows of the query. No big deal with 100 rows, potential issue with 1M rows.

    You can see it display the column headers from the columnNames collection of the Result, and then it iterates over each of the rows in the Result and across each column of each row.

    ReportServlet:

    import javax.servlet.jsp.jstl.sql.Result;
    import javax.servlet.jsp.jstl.sql.ResultSupport;
    
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        Connection c = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
    
        try {
            c = getConnection();
            ps = buildDBRequest(request);
            rs = ps.executeQuery();
            Result result = ResultSupport.toResult(rs);
            request.setAttribute("result", result);
            RequestDispatcher rd = request.getRequestDispatcher("/showResult.jsp");
            rd.forward(request, response);
        } catch(SQLException ex) {
            throw new ServletException(ex);
        } finally {
            close(c, ps, rs);
        }
    } 
    

    showResult.jsp

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Report Results</title>
        </head>
        <body>
            <h1>Report Results</h1>
            <table border="1">
                <!-- column headers -->
                <tr>
                    <c:forEach var="columnName" items="${result.columnNames}">
                        <th><c:out value="${columnName}"/></th>
                    </c:forEach>
                </tr>
                <!-- column data -->
                <c:forEach var="row" items="${result.rowsByIndex}">
                    <tr>
                        <c:forEach var="column" items="${row}">
                            <td><c:out value="${column}"/></td>
                        </c:forEach>
                    </tr>
                </c:forEach>
            </table>
        </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.