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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:18:18+00:00 2026-05-27T20:18:18+00:00

I have a jsp (itemSearch.jsp) to display all items based on user submission. Once

  • 0

I have a jsp (itemSearch.jsp) to display all items based on user submission. Once the user submits i am calling java method to submit all parameters as shown below

submitItems = itemManager.getProcessedItems(1, itemID, startPage, endPage, fromDate, toDate);

here in getProcessedItems i am fetching data using JDBC connection

public ArrayList getProcessedItems(1, itemID, startPage, endPage, fromDate, toDate) {
ArrayList p_items=new ArrayList();
Connection connection = null;
String sqlStatement = null;

try {
            connection = DBManager.getConnection(DBManager.EPM_DATASOURCE_NAME);
            if(set==1) {

                sqlStatement =  "SELECT I.lineid, I.date,S.STATUS, S.DATETIME, ";
                sqlStatement += "S.TOTAL FROM ITEM I, LITEM LI, ITEM_STATUS S ";
                sqlStatement += "WHERE I.LINEID=LI.ID AND I.ITEMID=? ";

                if (fromDate !=null && toDate!=null){
                    SimpleDateFormat fd = new SimpleDateFormat("MM/dd/yyyy");
                    String fromdateString = fd.format(fromDate);
                    String todateString = fd.format(toDate);
                    sqlStatement += " AND I.PDATE BETWEEN RANGE_DATE('" + fd.format(fromDate) + "','MM/DD/YYYY') AND RANGE_DATE('" + fd.format(toDate) + "','MM/DD/YYYY')";

                }           
                sqlStatement += "ORDER BY I.PDATE DESC";
            } 

            PreparedStatement ps = connection.prepareStatement(paginationBegin+sqlStatement+paginationEnd);
            ps.setInt(1, ID);
            ResultSet rs = ps.executeQuery();
            while(rs.next()) {
                if(items.contains(new Integer(rs.getInt("itemid")))==false) {
                items.add(new Integer(rs.getInt("itemid")));
                ReportItem ri = new ReportItem();
                 ri.setLineItemID(rs.getInt("lineid"));
                 ri.setTransmitted(rs.getTimestamp("idate"));
                 ri.setStatus(rs.getString("status"));
                 ri.setStatusDateTime(rs.getTimestamp("s_datetime"));
                 p_items.add(ri);
                }
               }
            rs.close();
            ps.close();
        } catch (SQLException e) {
            log("ERROR");
        } catch (NamingException e) {
            log("ERROR");
        } finally {
            DBManager.closeConnection(connection);
        }

        return p_items;
}

This properly displays data in itemSearch.jsp but now i want to add CSV file (hyperlink in jsp) which contains displayed data in the file for downloading.

i.e

<div align="right" class="TableRows" style="padding-right:10px"><a href="" class="TableRowLinks">CSV File</a></div> 

Questions
1. How to generate CSV file from queried result ?
2. How to give link for the same in jsp file?

  • 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-27T20:18:18+00:00Added an answer on May 27, 2026 at 8:18 pm

    You can use SuperCSV

    Why do you want to write in a JSP file?
    Use servlet for it, just create a file with .csv extension and write your response in it.

    Code Sample:

    class Order {
        Integer orderNumber;
        Integer parentOrder;
        Integer productNumber;
        String  userComment;
    
        public Integer getOrderNumber() {
            return orderNumber;
        }
        public void setOrderNumber(int orderNumber) {
            this.orderNumber = orderNumber;
        }
        public Integer getParentOrder() {
            return parentOrder;
        }
        public void setParentOrder(int parentOrder) {
            this.parentOrder = parentOrder;
        }
        public Integer getProductNumber() {
            return productNumber;
        }
        public void setProductNumber(int productNumber) {
            this.productNumber = productNumber;
        }
        public String getUserComment() {
            return userComment;
        }
        public void setUserComment(String userComment) {
            this.userComment = userComment;
        }
    }
    

    Writing partial objects to a CSV file

    public void should_partial_write() throws Exception {
        // The data to write
        Order mainOrder = new Order();
        mainOrder.setOrderNumber(1);
        mainOrder.setProductNumber(42);
        mainOrder.setUserComment("some comment");
        Order subOorder = new Order();
        subOorder.setOrderNumber(2);
        subOorder.setParentOrder(1);
        subOorder.setProductNumber(43);
    
        // for testing write to a string rather than a file
        StringWriter outFile = new StringWriter();
    
        // setup header for the file and processors. Notice the match between the header and the attributes of the
        // objects to write. The rules are that
        // - if optional "parent orders" are absent, write -1
        // - and optional user comments absent are written as ""
        String[] header = new String[] { "orderNumber", "parentOrder", "productNumber", "userComment" };
        CellProcessor[] Processing = new CellProcessor[] { null, new ConvertNullTo(-1), null, new ConvertNullTo("\"\"") };
    
        // write the partial data
        CsvBeanWriter writer = new CsvBeanWriter(outFile, CsvPreference.EXCEL_PREFERENCE);
        writer.writeHeader(header);
        writer.write(mainOrder, header, Processing);
        writer.write(subOorder, header, Processing);
        writer.close();
    
        // show output
        System.out.println(outFile.toString());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jsp with a submit based on the html:form action. <html:form action=/nextPath>
I have a JSP java application that has a name AAA-master so currently my
I have a jsp form validate.jsp which contains 2 text fields where user enters
We have jsp, which uses some java beans to create some variables to be
I have a .jsp page that begins with <%@ taglib uri=http://java.sun.com/jstl/core prefix=c %> <%@
I have a JSP page that will display the exact content of another web
I have a JSP with a managed bean. I want to display a message
I have jsp page and html form with button on this. How execute java
I have a jsp page where user can upload his details via file. but
I have a JSP page which shows items included in an Array (Just a

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.