/**
* Convert the content in the database to HTML
* Data contains fields in the database.
* Formid is the ID of the information in the database.
* Filepath is the location where the generated HTML file is stored
* @ Param Image
* @ Return
*/
Public void formtohtml (string data, string formid, string filepath ){
Stringbuffer Buf = new stringbuffer ("");
Buf. append ("<HTML> ");
Buf
. Append ("<meta http-equiv = 'content-type' content = 'text/html; charset = UTF-8 '/> ");
Buf. append ("<title> sdsds </title> ");
Buf. append ("Buf. append ("Buf. append ("<body> ");
Buf. append (data );
Buf. append ("</body> ");
Buf. append ("String filename = filepath + formid + ". html ";
Objectoutputstream objoutputstream;
Try {
Objoutputstream = new objectoutputstream (New fileoutputstream (
New file (filename )));
Objoutputstream. writeobject (BUF. tostring ());
} Catch (filenotfoundexception e ){
E. printstacktrace ();
} Catch (ioexception e ){
E. printstacktrace ();
}
}
/**
* Convert the content in the database to HTML
* The location where the vmbasepath VM template is stored, for example, D :\\ projectpath \ attach \ html
* Vmtempname VM Template Name
* Datacontext contains fields in the database.
* The path of HTML generated by htmlfilepath is: "D: \ projectpath \ attach \ HTML \ test.html"
* @ Param Image
* @ Return
*/
Public String datatohtml (string vmbasepath, string vmtempname,
String datacontext, string htmlfilepath) throws exception {
// Initialize and obtain the velocity Engine
Velocityengine VE = new velocityengine ();
// Set the path
Properties Properties = new properties ();
String basepath = vmbasepath;
// String basepath = "d :\\ projectpath \ attach \ html ";
Properties. setproperty (velocity. file_resource_loader_path, basepath );
Ve. INIT (properties );
// Obtain the velocity Template
// Template T = VE. gettemplate ("104.vm ");
Template T = VE. gettemplate (vmtempname );
// Obtain the context of Velocity
Velocitycontext context = new velocitycontext ();
// Enter the data in the context
// Context. Put ("name", "Liang ");
Context. Put ("name", datacontext );
// Output stream
Stringwriter writer = new stringwriter ();
// Conversion output
T. Merge (context, writer );
// Printwriter filewriter = new printwriter (New
// Fileoutputstream ("D: \ projectpath \ attach \ HTML \ test.html"), true );
Fileoutputstream Fos = new fileoutputstream (htmlfilepath );
Printwriter filewriter = new printwriter (FOS, true );
Filewriter. println (writer. tostring ());
Filewriter. Flush ();
Filewriter. Close ();
FOS. Flush ();
FOS. Close ();
System. Out. println ("output completed! ");
Return "success ";
}