积极的人在每一次忧患中都看到一个机会,而消极的人则在每个机会都看到某种忧患。
importjava.io.ByteArrayOutputStream;
importjava.io.FileOutputStream;
importjava.io.IOException;
importjava.io.OutputStreamWriter;
importjava.io.PrintWriter; importjavax.servlet.RequestDispatcher;
importjavax.servlet.ServletContext;
importjavax.servlet.ServletException;
importjavax.servlet.ServletOutputStream;
importjavax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
importjavax.servlet.http.HttpServletResponseWrapper; publicclasstoHtmlextendsHttpServlet
{ publicvoidservice(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException
{
Stringurl="";
Stringname=""; ServletContextsc=getServletContext(); Stringfile_name=request.getParameter("file_name");//你要访问的jsp文件,如index.jsp
//则你访问这个servlet时加参数.如http://localhost/toHtml?file_name=index url="/"+file_name+".jsp";//这是你要生成HTML的jsp文件,如
//http://localhost/index.jsp的执行结果. name="/home/resin/resin-2.1.6/doc/"+file_name+".htm";//这是生成的html文件名,如index.htm. RequestDispatcherrd=sc.getRequestDispatcher(url); finalByteArrayOutputStreamos=newByteArrayOutputStream(); finalServletOutputStreamstream=newServletOutputStream()
{
publicvoidwrite(byte[]data,intoffset,intlength)
{
os.write(data,offset,length);
} publicvoidwrite(intb)throwsIOException
{
os.write(b);
}
}; finalPrintWriterpw=newPrintWriter(newOutputStreamWriter(os)); HttpServletResponserep=newHttpServletResponseWrapper(response)
{
publicServletOutputStreamgetOutputStream()
{
returnstream;
} publicPrintWritergetWriter()
{
returnpw;
}
};
rd.include(request,rep);
pw.flush();
FileOutputStreamfos=newFileOutputStream(name);//把jsp输出的内容写到xxx.htm
os.writeTo(fos);
fos.close();
PrintWriterout=response.getWriter();
out.print("<palign=center><fontsize=3color=red>首页已经成功生成!Andrew</font></p>");
}
}
到此这篇关于javascriptp生成静态页面的方法就介绍到这了。岁前的周折经历,将是人生的一大笔财富。更多相关javascriptp生成静态页面的方法内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!