java 能做动态生静态的网站吗?能 怎么做 java 能做动态生静态的网站吗?能 怎么做 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 能不能给个用freeer动生静态的例子 当然可以啦,方法很多了,终究就是生成静态html 1 java.io 读html模板文件2 构造新的网页字符串3 java.io 写到一个新的文件里写文件例子FileOutputStream afile=new FileOutputStream(path+"/test.htm");PrintWriter pw=new PrintWriter(afile);pw.println(orgtxt);pw.close(); 我做过一个新闻发布系统。读取固定的模板和数据库的数据,生成html页面模板可以由美工去制作,使用人员负责录入数据,点击生成。1 java.io 读html模板文件 2 将模板中自定义的标签用数据库的内容给替换掉 (核心标签的制作)3 java.io 写到一个新的文件里 标签TagSupport可以去看看有关的资料。 去看 freeMarker的文档吧,虽然是英文的,不过写的非常细我这里只有很简单的几个。有兴趣你可以参考。http://www.java2000.net/f280 简单原理:HTML 文件 template.htm <body> This is my HTML page. <br> author:#author# 内容:#content# </body>JSP文件<% String 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); String title = ""; String editer = "作者"; String content = "这里是文章内容"; templateContent=templateContent.replaceAll("#title#",title); templateContent=templateContent.replaceAll("#author#",editer);//替换掉模块中相应的地方 templateContent=templateContent.replaceAll("#content#",content); String fileame = "new.html"; fileame = request.getRealPath("/")+fileame;//生成的html文件保存路径 out.print(templateContent); FileOutputStream fileoutputstream = new FileOutputStream(fileame);//建立文件输出流 byte tag_bytes[] = templateContent.getBytes(); fileoutputstream.write(tag_bytes); fileoutputstream.close();%> freeer,velocity,xslt,Taperstry等等等等都可以做的,自己选吧 关于.asmx webservice的问题,请高手指教下 JSP用递归展现论坛子贴的问题 req.getContentLength() servlet中RequestDispatcher.forward总是出现空指针异常 EL 问题 关于JSTL问题, 高手指点写哪里写错了 新开的!!!!! 从数据库中读出来的图片在页面不能图形化显示,全是二进制显示的乱码,怎么回事? JSP里面的代码是不是少HTML的差不多呢,只不过是有的注释%要加上部分是JSP特有代码呢? 传送300个值到另一个页面你有办法吗? 上传文件时如何取消????高手快来啊 !!! 急啊???
2 构造新的网页字符串
3 java.io 写到一个新的文件里
写文件例子
FileOutputStream afile=new FileOutputStream(path+"/test.htm");
PrintWriter pw=new PrintWriter(afile);
pw.println(orgtxt);
pw.close();
读取固定的模板和数据库的数据,生成html页面模板可以由美工去制作,使用人员负责录入数据,点击生成。1 java.io 读html模板文件
2 将模板中自定义的标签用数据库的内容给替换掉 (核心标签的制作)
3 java.io 写到一个新的文件里
标签TagSupport可以去看看有关的资料。
我这里只有很简单的几个。有兴趣你可以参考。http://www.java2000.net/f280
简单原理:HTML 文件 template.htm
<body>
This is my HTML page. <br>
author:#author#
内容:#content#
</body>JSP文件<% String 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); String title = "";
String editer = "作者";
String content = "这里是文章内容";
templateContent=templateContent.replaceAll("#title#",title);
templateContent=templateContent.replaceAll("#author#",editer);//替换掉模块中相应的地方
templateContent=templateContent.replaceAll("#content#",content);
String fileame = "new.html"; fileame = request.getRealPath("/")+fileame;//生成的html文件保存路径 out.print(templateContent);
FileOutputStream fileoutputstream = new FileOutputStream(fileame);//建立文件输出流
byte tag_bytes[] = templateContent.getBytes();
fileoutputstream.write(tag_bytes);
fileoutputstream.close();%>
都可以做的,自己选吧