日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

JSP頁面自動生成html頁面或任何格式頁面_JSP教程

編輯Tag賺U幣
教程Tag:暫無Tag,歡迎添加,賺取U幣!

推薦:用JSP來實現(xiàn)文件下載功能的幾種方式
1.最直接最簡單的,方式是把文件地址直接放到html頁面的一個鏈接中。這樣做的缺點是把文件在服務器上的路徑暴露了,并且還無法對文件下載進行其它的控制(如權限)。這個就不寫示例了。 2

先建立一個模本頁面:template.htm



###title###














###title###
作者:###author###
###content###



=========================================
再寫一個JSP頁面: buildhtml.jsp

<%@ page contentType="text/html; charset=gb2312" import="java.util.*,java.io.*"%>
<%
try{
String title="jsp生成靜態(tài)html文件";
String content="小樣,還搞不定你?";
String editer="mb5ucom";
String filePath = "";
filePath = request.getRealPath("/") "template.htm";
out.print(filePath);
String templateContent="";
FileInputStream fileinputstream = new FileInputStream(filePath);//讀取模塊文件
int lenght = fileinputstream.available();
byte bytes[] = new byte[lenght];
fileinputstream.read(bytes);
fileinputstream.close();
templateContent = new String(bytes);
out.print(templateContent);
templateContent=templateContent.replaceAll("###title###",title);
templateContent=templateContent.replaceAll("###content###",content);
templateContent=templateContent.replaceAll("###author###",editer);//替換掉模塊中相應的地方
out.print(templateContent);
// 根據(jù)時間得文件名
Calendar calendar = Calendar.getInstance();
String fileame = String.valueOf(calendar.getTimeInMillis()) ".html";
fileame = request.getRealPath("/") fileame;//生成的html文件保存路徑
FileOutputStream fileoutputstream = new FileOutputStream(fileame);//建立文件輸出流
out.print("文件輸出路徑:
");
out.print(fileame);
byte tag_bytes[] = templateContent.getBytes();
fileoutputstream.write(tag_bytes);
fileoutputstream.close();
}
catch(Exception e){
out.print(e.toString());
}
%>

分享:Servlet和Filter的url匹配url-pattern
  Servlet和filter是J2EE開發(fā)中常用的技術,使用方便,配置簡單,老少皆宜。   估計大多數(shù)朋友都是直接配置用,也沒有關心過具體的細節(jié),今天遇到一個問題,上網查了servlet的規(guī)范才

來源:模板無憂//所屬分類:JSP教程/更新時間:2008-08-22
相關JSP教程