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 957583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:43:38+00:00 2026-05-16T00:43:38+00:00

I need to render an HTML table from a Servlet, in response to an

  • 0

I need to render an HTML table from a Servlet, in response to an AJAX request. I’m wondering what the best way to go about this is? I’ve explored using an javax.faces.component.html.HtmlDataTable. One of the questions I have regarding this method is how to render the HTML once the table has been populated. From the looks of it, a FacesContext is required.

Any ideas?

  • 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-16T00:43:38+00:00Added an answer on May 16, 2026 at 12:43 am

    JSF isn’t what you’re looking for. It’s a component based MVC framework. Just do it either the easy and ugly way in a simple loop in the servlet:

    writer.write("<table>");
    for (Item item : items) {
        writer.write("<tr>");
        writer.write(String.format("<td>%s</td>", item.getFoo()));
        writer.write(String.format("<td>%s</td>", item.getBar()));
        writer.write("</tr>");
    }
    writer.write("</table>");
    

    Or store it as request attribute and forward to a JSP

    request.setAttribute("items", items);
    request.getRequestDispatcher("items.jsp").forward(request, response);
    

    Which in turn basically contains the following:

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <table>
        <c:forEach items="${items}" var="item">
            <tr>
                <tr>${item.foo}</td>
                <tr>${item.bar}</td>
            </tr>
        </c:forEach>
    </table>
    

    Or rather look for a different and more flexible data format like JSON so that the client has the freedom how to render it. Here’s an example which uses Google Gson.

    writer.write(new Gson().toJson(items));
    

    Which you can render into a table using jQuery as follows:

    $.getJSON('json/items', function(items) {
        var table = $('#someelement').append('<table>');
        $(items).each(function(i, item) {
            var row = table.append('<tr>');
            row.append('<td>').text(item.foo);
            row.append('<td>').text(item.bar);
        });
    });
    

    See also:

    • What is the difference between JSP, Servlet and JSF?
    • JSON from Servlet to HTML table
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to display data from a database in a html table. I am
Can somebody recommend the best (and preferably portable) way to render HTML documents onto
Let's just say that I need to render a certain amount of HTML over
I'm looking for a way to generate pdf files from html In order to
i need to create an html report where i've to put a table into.
I need a MultiWidgets that renders HTML like following as a MultiValueField : <div
I need to render a partial view to a string within a controller action.
I need to render a 1027 * 768 bitmap to the client window (same
I'm using Backbone.Marionette and need to render a view of employees and their respective
I'm writing a game in python with pygame and need to render text onto

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.