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

JSP頁(yè)面自動(dòng)生成html頁(yè)面或任何格式頁(yè)面_JSP教程

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

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

先建立一個(gè)模本頁(yè)面:template.htm



###title###














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



=========================================
再寫(xiě)一個(gè)JSP頁(yè)面: 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);//替換掉模塊中相應(yīng)的地方
out.print(templateContent);
// 根據(jù)時(shí)間得文件名
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開(kāi)發(fā)中常用的技術(shù),使用方便,配置簡(jiǎn)單,老少皆宜。   估計(jì)大多數(shù)朋友都是直接配置用,也沒(méi)有關(guān)心過(guò)具體的細(xì)節(jié),今天遇到一個(gè)問(wèn)題,上網(wǎng)查了servlet的規(guī)范才

來(lái)源:模板無(wú)憂//所屬分類(lèi):JSP教程/更新時(shí)間:2008-08-22
相關(guān)JSP教程