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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:15:04+00:00 2026-06-14T22:15:04+00:00

I am able to generate the excel file in server system,but the problem is

  • 0

I am able to generate the excel file in server system,but the problem is whenever i am trying to access this from client system it is generating in server system only not in client system.the following code is used to generate the excel file:

<%@ page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFRow"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFCell"%>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="javax.swing.JFileChooser" %>
<%@ page import="java.awt.Desktop"%>
<%@ page isErrorPage='true' %>


<%! 
    Connection conn = null;
    String url = "jdbc:mysql://localhost:3306/";
    String dbName = "s";
    String driver = "com.mysql.jdbc.Driver";
    String username = "root"; 
    String userPassword = "s";

%>
<br><br>
<%

    java.util.Date date = new java.util.Date();

    JFileChooser chooseFile=new JFileChooser();

    chooseFile.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooseFile.setDialogTitle("Select a Directory");

    chooseFile.showDialog(null,"Click Me to Save the Folder");
    //String filename = "/tmp/Excel "+System.currentTimeMillis() +".xls" ;




try
{

     Class.forName(driver).newInstance();
         conn = DriverManager.getConnection(url+dbName,username,userPassword);

      Statement stmt = conn.createStatement();
      String strQuery = "select * from  Meter_List";

      ResultSet rs = stmt.executeQuery(strQuery);


          HSSFWorkbook hwb = new HSSFWorkbook();
          HSSFSheet sheet = hwb.createSheet("new sheet");

          HSSFRow rowhead = sheet.createRow((short)2);
          rowhead.createCell(0).setCellValue("SNo");
          rowhead.createCell(1).setCellValue("Meterid");
          rowhead.createCell(2).setCellValue("Consumerid");
          rowhead.createCell(3).setCellValue("Consumername");
          rowhead.createCell(4).setCellValue("LastReading");
          rowhead.createCell(5).setCellValue("Date");
          rowhead.createCell(6).setCellValue("Time");
          rowhead.createCell(7).setCellValue("Status");
          rowhead.createCell(8).setCellValue("Subzone");
          rowhead.createCell(9).setCellValue("Zone");

          int index=3;
          int sno=0;
          String name="";
           while(rs.next()) 
       {
                sno++;

                HSSFRow row = sheet.createRow((short)index);
                row.createCell(0).setCellValue(sno);
                row.createCell(1).setCellValue(rs.getInt("Meterid"));
                row.createCell(2).setCellValue(rs.getInt("Consumerid"));
                row.createCell(3).setCellValue(rs.getString("Consumername"));
                row.createCell(4).setCellValue(rs.getInt("lastreading"));
                row.createCell(5).setCellValue(rs.getDate("Date"));
                row.createCell(6).setCellValue(rs.getTime("Time"));
                row.createCell(7).setCellValue(rs.getString("Status"));
                row.createCell(8).setCellValue(rs.getString("Subzone"));
                row.createCell(9).setCellValue(rs.getString("Zone"));
                index++;
       }

          FileOutputStream fileOut = new FileOutputStream(filename);
          hwb.write(fileOut);
          fileOut.close();
          out.println("<b>Opening worksheet, please wait......</b><br>");

          Desktop dt=Desktop.getDesktop();
          dt.open(new File(filename));
          out.println("<b>Worksheet opened. It is saved as -\n\t\t </b><br>"+filename);
} 
catch ( Exception ex ) 
{  
    //out.println("Error :: "+ex);
    out.println("");
} 
%>
can you please help to solve this.
  • 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-06-14T22:15:06+00:00Added an answer on June 14, 2026 at 10:15 pm
    <%@ page language="java" import="java.io.*" %>
    <%@ page import="java.util.*" %>
    <%@ page import="java.sql.*" %>
    <%@ page import="javax.swing.JFileChooser" %>
    <%@ page import="java.awt.Desktop"%>
    <%@ page isErrorPage='true' %>
    <%@ page import="java.text.SimpleDateFormat"%>
    <%! 
        Connection conn = null;
        String url = "jdbc:mysql://localhost:3306/";
        String dbName = "su";
        String driver = "com.mysql.jdbc.Driver";
        String username = "root"; 
        String userPassword = "s";
    
    %>
    
    
    
    <%
        String filename="";
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-Disposition","inline;filename=" + "excel_sheet"+".xls");
        response.setHeader("Cache-Control","no-cache");
        PrintWriter pout = response.getWriter();
        String date1="";
        String time="";
    try
    {
    
            Class.forName(driver).newInstance();
                conn = DriverManager.getConnection(url+dbName,username,userPassword);
                Statement stmt = conn.createStatement();
            String strQuery = "select * from  Meter_List";
            ResultSet rs = stmt.executeQuery(strQuery);
            int index=3;
                int sno=0;
                String name="";
                    pout.print("SNo\t");
                    pout.print("MeterID\t"  );
                    pout.print("ConsumerID\t" );
                    pout.print("ConsumerName\t" );
    
                    pout.println();
                while(rs.next()) 
    
                         {
                                    int meterid = rs.getInt("Meterid");
                            int consumerid=rs.getInt("Consumerid");
                            String consumername = rs.getString("Consumername");
    
                                    sno++;
                            pout.print(sno + "\t");
                            pout.print(meterid + "\t" );
                            pout.print(consumerid + "\t" );
                                    pout.print(consumername + "\t");
    
                            index++;
                            pout.println();
    
                         }
    
    } 
    catch ( Exception ex ) 
    {  
        //out.println("Error :: "+ex);
        out.println("");
    } 
    %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am able to generate SHA-1 hash for a whole file. I did this
Is there any API or command-line able to generate a VSTemplate file from a
I am able to generate a link using my file upload system, now after
I have been trying to generate data in Excel. I generated .CSV file. So
I'm trying to upload Excel (2003) file into Sql server 2005. At present we
I'm able to generate a hierarchy with a recursive CTE but I have always
I wish to be able to generate URL variables like this: http://example.com/195yq http://example.com/195yp http://example.com/195yg
I'd like to be able to generate a class that inherits from BitmapData at
So I've been able to successfully generate an IJavaProject from within my Eclipse Plug-In,
I'm able to generate patch files from one version to another using NSIS' Vpatch.

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.