Import java. io. ByteArrayOutputStream;
Import java. io. File;
Import java. io. FileOutputStream;
Import java. io. IOException;
Import java. io. OutputStreamWriter;
Import java. io. PrintWriter;
Import javax. servlet. RequestDispatcher;
Import javax. servlet. ServletContext;
Import javax. servlet. ServletException;
Import javax. servlet. ServletOutputStream;
Import javax. servlet. http. HttpServlet;
Import javax. servlet. http. HttpServletRequest;
Import javax. servlet. http. HttpServletResponse;
Import javax. servlet. http. HttpServletResponseWrapper;
Public class ToHtml extends HttpServlet {
Public void Service (httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {
String url = "";
String name = "";
Servletcontext SC = getservletcontext ();
String file_name = request. getparameter ("file_name ");
Url = "/JSP/wzgmanager/manageruser. jsp ";
// This is the generated HTML file name, such as index.htm.
Name = "/jsp/wzgManager/managerUser.doc ";
Name = getServletContext (). getRealPath (name );
RequestDispatcher rd = SC. getRequestDispatcher (url );
Final ByteArrayOutputStream OS = new ByteArrayOutputStream ();
Final ServletOutputStream stream = new ServletOutputStream (){
Public void write (byte [] data, int offset, int length ){
OS. write (data, offset, length );
}
Public void write (int B) throws IOException {
OS. write (B );
}
};
Final PrintWriter pw = new PrintWriter (new OutputStreamWriter (OS ));
HttpServletResponse rep = new HttpServletResponseWrapper (response ){
Public ServletOutputStream getOutputStream (){
Return stream;
}
Public PrintWriter getWriter (){
Return pw;
}
};
Rd. Include (request, Rep );
PW. Flush ();
// Write the content of the jspoutput to xxx.htm.
File file = new file (name );
If (! File. exists ()){
File. createnewfile ();
}
System. Out. println (name );
Fileoutputstream Fos = new fileoutputstream (File );
OS. writeto (FOS );
FOS. Close ();
Response. setcontenttype ("text/html; charset = GBK ");
Printwriter out = response. getwriter ();
Out. Print ("<p align = center> <font size = 3 color = Red> the homepage is successfully generated! Andrew </font> </P> ");
}
}