Display and save the content in JSP in the form of word, and add a sentence at the top of JSP!
<% @ Page contenttype = "application/MSWord; charset = GBK" %>
In JSP, data is imported directly into the word document as a "file stream", but that is the case (No format)
File file = new file ("F:/work/sgcc_project/sgcc/progress/histogram/doc1.htm ");
System. Out. println ("======= --------");
Fileinputstream is = NULL;
Bufferedoutputstream Bos = NULL;
Try {
Request. setcharacterencoding ("iso_8859_1 ");
// Response. Reset ();
Response. setcontenttype ("application/vnd. MS-word; charset = 8859_1 ");
Response. setheader ("content-disposition", "attachment; filename =" + "aa.doc ");
Is = new fileinputstream (File );
Bos = new bufferedoutputstream (response. getoutputstream ());
Byte [] buffer = new byte [2048];
While (is. Read (buffer )! =-1 ){
Bos. Write (buffer );
}
// String S = "";
// S. getbytes ();
} Catch (unsupportedencodingexception e ){
E. printstacktrace ();
} Catch (filenotfoundexception e ){
E. printstacktrace ();
} Catch (ioexception e ){
E. printstacktrace ();
} Finally {
Try {
Bos. Flush ();
Bos. Close ();
Is. Close ();
// File. Delete ();
} Catch (ioexception e ){}
}
Read the content in Word wordextractor with a te-extractors-0.4.jar package, the te-extractors-0.4.jar is the poi under apahce. New jar package Encapsulation
Fileinputstream in = new fileinputstream ("D: // test.doc ");
Wordextractor extractor = new wordextractor ();
String STR = extractor. extracttext (in );
System. Out. println ("the result length is" + Str. Length ());
System. Out. println ("the result is" + Str );
Sprmoperation so = NULL;