社区
Java EE
帖子详情
jsp如何自动生成静态页面--急啊,在线等
tender_hui
2007-06-11 10:23:57
有谁知道从数据库调出来数据后,再自动生成静态页面
...全文
191
4
打赏
收藏
jsp如何自动生成静态页面--急啊,在线等
有谁知道从数据库调出来数据后,再自动生成静态页面
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
4 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
cyhs03
2007-06-11
打赏
举报
回复
上面用Servlet做的一个向数据库添加数据时就动态生成的一个静态页面
cyhs03
2007-06-11
打赏
举报
回复
package servlet;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.sql.SQLException;
import java.util.Calendar;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import Ueser.DealString;
import biz.Newbiz;
import dto.Dto;
public class Addnews extends HttpServlet {
String filename="";
String url="";
String author="";
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String title = request.getParameter("title");
title = new String(title.getBytes("iso-8859-1"),"gb2312");
String content = request.getParameter("content");
content = new String(content.getBytes("iso-8859-1"),"gb2312");
Dto dto = new Dto();
dto = (Dto)request.getSession().getAttribute("user");
author =dto.getUsername();
url = generateHtml(request);
String imageurl = request.getScheme() +"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/upload/"+filename;
Newbiz biz;
try {
biz = new Newbiz();
dto.setTitle(title);
dto.setContent(content);
dto.setAuthor(author);
dto.setUrl(url);
dto.setImageurl(imageurl);
int i = biz.insertnew(dto);
if(i==1)
{
response.sendRedirect("/news/Selectnews");
}else
{
response.sendRedirect("/tongxi/error.html");
}
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
public String generateHtml(HttpServletRequest request)
{
String createtime = DealString.getDateTime();
String templateFilePath =
request.getScheme()+
"://"
+ request.getServerName()
+ ":"
+ request.getServerPort()
+ request.getContextPath()
+ "/news.html";
//System.out.println(templateFilePath);
String templateContent = "";
FileInputStream fileinputstream;
try {
fileinputstream = new FileInputStream("F:/work1/news/news.html");
int lenght = fileinputstream.available();
byte bytes[] = new byte[lenght];
fileinputstream.read(bytes);
fileinputstream.close();
templateContent = new String(bytes);
} catch (FileNotFoundException e) {
System.err.println("输入文件找不到");
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
String title = request.getParameter("title");
String content = request.getParameter("content");
try {
title = new String(title.getBytes("iso-8859-1"),"gb2312");
content = new String(content.getBytes("iso-8859-1"),"gb2312");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
String imageurl = request.getScheme()
+"://"+request.getServerName()
+":"+request.getServerPort()+request.getContextPath()+"/upload/"+filename;
templateContent = templateContent.replaceAll("###title###", title);
templateContent = templateContent.replaceAll("###author###",author);
templateContent = templateContent.replaceAll("###createtime###", createtime);
templateContent = templateContent.replace("###imageurl###", imageurl);
templateContent = templateContent.replaceAll("###content###",content);
Calendar calendar = Calendar.getInstance();
String htmlFileName = String.valueOf(calendar.getTimeInMillis())+ ".html";
String tomcatPath = request.getRealPath("/") + "news\\" + htmlFileName;
String eclipsePath = "F:/work1/news/news/" + htmlFileName;
System.out.println(tomcatPath);
System.out.println(eclipsePath);
String uurl = request.getScheme()
+ "://"
+ request.getServerName()
+ ":"
+ request.getServerPort()
+ request.getContextPath()
+"/news/"
+ htmlFileName;
try
{
FileOutputStream tomcatOutputStream;
tomcatOutputStream = new FileOutputStream(tomcatPath);
FileOutputStream eclipseOutputStream = new FileOutputStream(eclipsePath);
byte tag_bytes[] = templateContent.getBytes();
tomcatOutputStream.write(tag_bytes);
tomcatOutputStream.close();
eclipseOutputStream.write(tag_bytes);
eclipseOutputStream.close();
}
catch (FileNotFoundException e)
{
System.err.println("输出文件找不到");
}
catch (IOException e)
{
e.printStackTrace();
}
return uurl;
}
}
tender_hui
2007-06-11
打赏
举报
回复
能不能具体一点,谢谢
hosenbin
2007-06-11
打赏
举报
回复
那要用IO流才行啊
jsp
网站的
静态
页面
生成方案
提升网站性能的方式有很多,例如有效的使用缓存,生成
静态
页面
等等。今天要说的就是生成
静态
页面
的方式。什么叫生成
静态
页面
呢?很简单,例如我们如果访问一个链接 http://xyz.com/index.do,那么服务器就会解析这个请求,让特定的Action 去处理。这其中的缺点是显而易见的:如果访问的人,那么就会加重应用服务器的压力,最恶劣的后果就是应用服务器down
JSP
动态
页面
转
静态
实例教程
本文还有配套的精品资源,点击获取 简介:在IT领域,将
JSP
动态
页面
转化为
静态
HTML
页面
是一项优化策略,用于提升网站速度、减轻服务器负担并优化搜索引擎排名。本实例将指导如何使用MyEclipse这一Java开发工具进行
JSP
静态
化。内容包括动态与
静态
页面
的区别、
静态
化的必要性、使用MyEclipse进行
静态
化的过程,以及不同的
静态
化策略和实施中应注意的事项。 1...
html和
jsp
的区别--
静态
页面
和动态
页面
的区别
一、
静态
web
页面
,一般指html: 1、在
静态
Web程序中,客户端使用Web浏览器(IE、FireFox等)经过网络(Network)连接到服务器上,使用HTTP协议发起一个请求(Request),告诉服务器我现在需要得到哪个
页面
,所有的请求交给Web服务器,之后WEB服务器根据用户的需要,从文件系统(存放了所有
静态
页面
的磁盘)取出内容。之后通过Web服务器返回给客户端,客户端接收到内容之后经过浏览器渲染解析,得到显示的效果。 2、为了让
静态
web
页面
显示更加好看,使用javascript/VBScr
多语言网站生成
静态
页面
实现思路以及用freemarker作模板生成
静态
页面
的实现
现在呀,越来越多的网站要求做成多种语言,并且,大家好像都知道了html比动态的运行快,所以,也倾向
自动生成
静态
页面
这个功能,我就纳闷了,消息怎么传的那么快呀!好吧,说说多语言网站生成
静态
页面
时候的主要瓶颈在哪些方面吧: 1.首先是列表类型的文章分页的生成 这个吧,肯定需要有自己的一套规则,这次我生成
静态
页面
时候是这样规定的: 列表页:第n页:list_1_n.htm(其实,那个_1暂时没用,
动态
页面
生成
静态
页面
的原理
真
静态
与伪
静态
目前网络上好多网站的新闻发布系统都采用了动态服务器技术生成
静态
HTML的做法,这样做的好处是:一是能减轻其服务器的负担,二是因为生成了HTML
静态
页面
,所以其网站被搜索引擎搜索到的机率更大一些。因此,在这里,想简单地谈一下这种做法的思路。这篇文章适合于对PHP+MYSQL数据库操作,SQL语句以及网页设计有点基础的朋友,如果您是一个从头开始学的朋友,那么请先打好基础吧!到这里
Java EE
67,549
社区成员
225,860
社区内容
发帖
与我相关
我的任务
Java EE
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
复制链接
扫一扫
分享
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章