Develop Spring MVC Apps with JBuilder2005 - Display PDF / Excel Documentation
Gaoke Hua
About the author: Gao Jinghua, Nanjing Aviation College computing a master's degree in mathematics, more than ten years of corporate informationization work experience. Current research interest, J2EE enterprise application, ERP software research and development, data warehouse system research and development.
1. Follow the "Spring MVC Application" with JBuilder 2005 "- Establish a Spring Application with the representation layer technology XSLT integrated article 2. Add POI, IText Class Library 3. Modify Views.Properties files
/Web-inf/classes/views.properties
Home.class = xslt.homepage
Home.stylesheetLocation = / Web-inf / xsl / home.xslt
Home.Root = Words
XL.class = Excel.homepage
Pdf.class = pdf.pdfpage
4. Add two class files
/src/excel/homepage.java
Package Excel;
Import java.util. *;
Import javax.servlet.http. *;
Import org.apache.poi.hssf.usermodel. *;
Import org.springframework.Web.Servlet.View.Document. *;
Public class homepage extends AbstractExcelView {
Protected void BuildExceldocument
Map model,
HSSFWORKBOOK WB,
HTTPSERVLETREQUEST REQ,
HttpservletResponse Resp) throws Exception {
HSSFSHEET Sheet;
HSSFrow SheetRow;
HSSFCell Cell;
// go to the first sheet
// getSheetat: Only if wb is created from an existing document
// Sheet = wb.getsheetat (0);
Sheet = wb.createsheet ("Spring");
Sheet.SetDefaultColumnWidth ((Short) 12);
// Write a Text AT A1
Cell = getcell (Sheet, 0, 0);
SetText (Cell, "Spring-Excel Test");
List word = (list) Model.get ("wordlist");
For (int i = 0; i Cell = getcell (Sheet, 2 i, 0); SetText (string) Words.get (i)); } } } /Web-inf/pdf/pdfpage.java Package PDF; Import java.util. *; Import java.util.list; Import javax.servlet.http. *; Import com.lowagie.text. *; Import com.lowagie.text.pdf. *; Import org.springframework.Web.Servlet.View.Document. *; Public class pdfpage extends Abstractpdfview { Protected void Buildpdfdocument Map model, Document Doc, Pdfwriter Writer, HTTPSERVLETREQUEST REQ, HttpservletResponse Resp) throws Exception { List word = (list) Model.get ("wordlist"); For (int i = 0; i Doc.add (new paragraph ((String) Words.get (i))) } } } 5. Modify HomePageController.java Return New ModelandView ("HOME", MAP); Changing Home is XL or PDF. You can see different results.