Import Java. io. bytearrayoutputstream; <br/> Import Java. io. fileoutputstream; <br/> Import Java. io. ioexception; <br/> Import Java. io. outputstreamwriter; <br/> Import Java. io. printwriter; <br/> Import javax. servlet. requestdispatcher; <br/> Import javax. servlet. servletcontext; <br/> Import javax. servlet. servletexception; <br/> Import javax. servlet. servletoutputstream; <br/> Import javax. servlet. HTTP. httpservle T; <br/> Import javax. servlet. HTTP. httpservletrequest; <br/> Import javax. servlet. HTTP. httpservletresponse; <br/> Import javax. servlet. HTTP. httpservletresponsewrapper; <br/> public class tohtml extends httpservlet <br/> {<br/> Public void Service (httpservletrequest request, httpservletresponse response) throws servletexception, ioexception <br/> {<br/> string url = ""; <br/> string name = ""; <br/> servletcon Text SC = getservletcontext (); <br/> string file_name = request. getparameter ("file_name"); // the JSP file you want to access, such as index. JSP <br/> // Add parameters when you access this servlet. for example, http: // localhost/tohtml? File_name = index <br/> url = "/" + file_name + ". JSP "; // This is the JSP file you want to generate HTML, such as <br/> // http: // localhost/index. JSP execution result. <br/> name = "/home/resin-2.1.6/doc/" + file_name + ". htm "; // The generated HTML file name, such as index.htm. <br/> requestdispatcher RD = SC. getrequestdispatcher (URL); <br/> final bytearrayoutputstream OS = new bytearrayoutputstream (); <br/> final servletoutputstream stream = new servletoutputstream () <br/> {<br/> IC void write (byte [] data, int offset, int length) <br/>{< br/> OS. write (data, offset, length); <br/>}< br/> Public void write (int B) throws ioexception <br/>{< br/> OS. write (B); <br/>}< br/>}; <br/> final printwriter PW = new printwriter (New outputstreamwriter (OS )); <br/> httpservletresponse rep = new httpservletresponsewrapper (response) <br/>{< br/> Public servletoutputstream getoutputstream () <br/> {< Br/> return stream; <br/>}< br/> Public printwriter getwriter () <br/>{< br/> return PW; <br/>}< br/>}; <br/> Rd. include (request, Rep); <br/> PW. flush (); <br/> fileoutputstream Fos = new fileoutputstream (name); // write the jspoutput content to xxx.htm <br/> OS. writeto (FOS); <br/> FOS. close (); <br/> printwriter out = response. getwriter (); <br/> out. print ("<p align = center> <font size = 3 color = Red> the homepage is successfully generated! Andrew </font> </P> "); <br/>}< br/>}