
How to present the content of the newly created excel file in the following jsp to the web browser:
<%@ page import="java.io.InputStream" %>
<%@ page import="org.apache.poi.xssf.usermodel.XSSFSheet"%>
<%@ page import="org.apache.poi.xssf.usermodel.XSSFWorkbook"%>
<%@ page contentType="application/vnd.ms-excel" %>
<%@ page import="java.io.*" %>
<%
try {
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet1 = wb.createSheet("TA");
XSSFSheet sheet2 = wb.createSheet("TM");
XSSFSheet sheet3 = wb.createSheet("XFA");
XSSFSheet sheet4 = wb.createSheet("OTHERS");
FileOutputStream fileOut = new FileOutputStream
("c:\\excel\\test.xlsx");
wb.write(fileOut);
fileOut.close();
} catch ( Exception ex ) {
}
%>
}

<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<%@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"%>
<table border="1">
<%
short a=0;
short b=1;
short c=2;
short d=3;
int i=0;
String value1="", value2="",value3=" ", value4="";
String filename ="C:/hello.xls";
if(filename != null && !filename.equals("")){
try{
FileInputStream fs =new FileInputStream(filename);
HSSFWorkbook wb = new HSSFWorkbook(fs);
for(int k = 0; k < wb.getNumberOfSheets(); k++){
int j=i+1;
HSSFSheet sheet = wb.getSheetAt(k);
int rows = sheet.getPhysicalNumberOfRows();
for(int r = 0; r < rows; r++){
HSSFRow row = sheet.getRow(r);
int cells = row.getPhysicalNumberOfCells();
out.write("<br>");
HSSFCell cell1 = row.getCell(a);
value1 = cell1.getStringCellValue();
HSSFCell cell2 = row.getCell(b);
value2 = cell2.getStringCellValue();
HSSFCell cell3 = row.getCell(c);
value3 = cell3.getStringCellValue();
HSSFCell cell4 = row.getCell(d);
value4 = cell4.getStringCellValue();
%>
<tr><td><%=value1%></td><td><%=value2%></td><td><%=value3%></td><td><%=value4%></td></tr>
<%
}
i++;
}
}
catch(Exception e){
System.out.println(e);
}
}
%>
</table>

Thanks for the answers, you are excellent! one more followup questions: May I add some user actions: such as update the cells then update the excel files. thanks so lot!
looking forward to your answers!

does the solution to the original questions work for the excel with multiple sheets and complicated content:
for instance: the excel file looks like:
tree structure: value1----6
a1
a2
a3
sheet1 sheet2 sheet3 sheet4 button: update
after the user update the excell from the browser, how to allow the user to update the excel.

Does anyone know how to add a browse upload functionally to this code? This code automatically does it and this is incorrect by my standards
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.