net.sf.flatpack.examples.jsptableexample.pzfilereaderwebsamples.index.jsp Maven / Gradle / Ivy
Go to download
Examples to handle CSV, Excel CSV, Tab, Pipe delimiters, just to name a few.
Maps column positions in the file to user friendly names via XML. See FlatPack Feature List under News for complete feature list.
<%@ page language="java" import="java.util.*,net.sf.pzfilereader.*,net.sf.pzfilereader.ordering.*,java.io.File" %>
PZ File Reader JSP Sample
<%
OrderBy order = null;
try{
File mappingFile = null;
File txtFile = null;
String appDirectory = null;
//find out where this application is installed
appDirectory = getServletContext().getRealPath("");
mappingFile = new File (appDirectory + "/PEOPLE.pzmap.xml");
txtFile = new File (appDirectory + "/PEOPLE.txt");
//read in the file
final PZParser pzparser = DefaultPZParserFactory.getInstance().newDelimitedParser(mappingFile,
txtFile, ',', 0, false) ;
final DataSet ds = pzparser.parse();
//check to see if there is a paramter in the request that is telling us what column to sort by
if (request.getParameter("orderby") != null &&
request.getParameter("orderby").trim().length() > 0){
//sort the file by what was passed in the request
order = new OrderBy();
order.addOrderColumn(new OrderColumn(request.getParameter("orderby"),false)); //set boolean to true for DESC sort
ds.orderRows(order);
}
}catch(Exception ex){
out.println("Error: " + ex);
}
%>
First Name
Last Name
Address
City
State
Zip
<%
while (ds.next()){
%>
<%=ds.getString("FIRSTNAME")%>
<%=ds.getString("LASTNAME")%>
<%=ds.getString("ADDRESS")%>
<%=ds.getString("CITY")%>
<%=ds.getString("STATE")%>
<%=ds.getString("ZIP")%>
<%
}
%>
© 2015 - 2025 Weber Informatics LLC | Privacy Policy