国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

jsp生成靜態(tài)頁面的詳細(xì)教程

2024-09-05 00:18:04
字體:
供稿:網(wǎng)友

  今天小編給大家分享一篇jsp生成靜態(tài)頁面的詳細(xì)教程,感興趣的朋友跟小編一起來了解一下吧!

  復(fù)制代碼 代碼如下:

  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

  //則你訪問這個(gè)servlet時(shí)加參數(shù).如http://localhost/toHtml?file_name=index

  url="/"+file_name+".jsp";//這是你要生成HTML的jsp文件,如

  //http://localhost/index.jsp的執(zhí)行結(jié)果.

  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輸出的內(nèi)容寫到xxx.htm

  os.writeTo(fos);

  fos.close();

  PrintWriterout=response.getWriter();

  out.print("首頁已經(jīng)成功生成!Andrew=3color=red>=center>

");

?

  }

  }

  以上就是jsp生成靜態(tài)頁面的詳細(xì)教程,想必都了解了吧,更多相關(guān)內(nèi)容請(qǐng)繼續(xù)關(guān)注錯(cuò)新技術(shù)頻道。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 景泰县| 左权县| 茶陵县| 潞西市| 马关县| 兴宁市| 汪清县| 乡城县| 淮阳县| 疏附县| 平泉县| 德清县| 乳山市| 富顺县| 吉木萨尔县| 赤壁市| 惠水县| 贵德县| 陇西县| 大方县| 十堰市| 克什克腾旗| 修武县| 于都县| 泊头市| 石屏县| 泌阳县| 河北区| 富平县| 桦甸市| 银川市| 拉萨市| 同仁县| 张家界市| 阿拉尔市| 临夏市| 通化市| 当阳市| 布拖县| 竹北市| 高碑店市|