社区
Java EE
帖子详情
jsp如何自动生成静态页面--急啊,在线等
tender_hui
2007-06-11 10:23:57
有谁知道从数据库调出来数据后,再自动生成静态页面
...全文
225
4
打赏
收藏
jsp如何自动生成静态页面--急啊,在线等
有谁知道从数据库调出来数据后,再自动生成静态页面
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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
生成
静态
页面
Jsp
生成
静态
页面
为了减轻服务器压力,将原来的文章管理系统由
jsp
生成
静态
页面
使用
jsp
生成
静态
页面
.整个工程的目录结构如图: StaticPage是我们将要生成的
静态
页面
目录 所有
静态
页面
都会生成在这个目录.然后编写一个MyFitler的过滤器: 以下是代码片段: package com.filter; impo
jsp
页面
内引入
静态
html,
JSP
技术实现动态
页面
到
静态
页面
的方法
本文是介绍了
jsp
技术实现动态
页面
到
静态
页面
的方法,分享给大家,具体如下:对于
JSP
技术实现动态
页面
到
静态
页面
的方案,我们从三个步骤来说明:
JSP
技术实现动态
页面
到
静态
页面
的方案第一:为了能深入浅出的理解这个框架的由来,我们首先来了解一下
JSP
解析器将我们写的
JSP
代码转换成的JAVA文件的内容。下面是一个
JSP
文件test.
jsp
﹤%@ page language=java contentTyp...
JSP
生成
静态
页面
-Tomcat提高性能之王道
常见的分类信息首页,需读取至少六次数据库;其他子
页面
,五至十几次次不等。 在使用数据库连接池的情况下,Tomcat可以支撑的并发量也十分有限。系统资源主要消耗在两方面: 1、数据库操作,频繁的从数据库返回结果; 2、Tomcat解析JAVA文件。 将动态
页面
按一定规则创建一匹.html纯
静态
页面
的过程,称之为生成
静态
页面
。 优点 无须访问数据库,节省了最大的系统消耗。
Java EE
67,535
社区成员
225,852
社区内容
发帖
与我相关
我的任务
Java EE
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
复制链接
扫一扫
分享
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章