package html;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Calendar;
/**
* @ClassName: CreateHtmlUtils
* @Description: Java 根据模板创建 html
* @author
* @date 2016年4月22日 下午3:51:16
*/
public class CreateHtmlUtils {
public static void main(String[] args) {
String filePath = "C:\\html\\template.html";
String imagePath ="http://localhost:8080/ecp/upload/1461293787628/1461293787628.jpg";
String disrPath = "c:\\html\\";
String fileName = "liuren";
Connection con;
//驱动程序名
String driver = "com.mysql.jdbc.Driver";
//URL指向要访问的数据库名mydata
String url = "jdbc:mysql://localhost:3306/html";
//MySQL配置时的用户名
String user = "root";
//MySQL配置时的密码
String password = "5209050";
//遍历查询结果集
try {
//加载驱动程序
Class.forName(driver);
//1.getConnection()方法,连接MySQL数据库!!
con = DriverManager.getConnection(url,user,password);
if(!con.isClosed())
System.out.println("Succeeded connecting to the Database!");
//2.创建statement类对象,用来执行SQL语句!!
Statement statement = con.createStatement();
//要执行的SQL语句
String sql = "select * from movie where status=0";
//3.ResultSet类,用来存放获取的结果集!!
ResultSet rs = statement.executeQuery(sql);
System.out.println("-----------------");
System.out.println("执行结果如下所示:");
System.out.println("-----------------");
System.out.println("姓名" + "\t" + "职称");
System.out.println("-----------------");
String title = null;
String keywords = null;
String descriptions = null;
String pic = null;
String urlhtml = null;
String pic1 = null;
String pic2 = null;
String pic3 = null;
String pic4 = null;
String pic5 = null;
String pic6 = null;
String htmlname = null;
String miaoshu=null;
String mname=null;
while(rs.next()){
//获取stuname这列数据
title = rs.getString("title");
//获取stuid这列数据
keywords = rs.getString("keywords");
descriptions = rs.getString("descriptions");
pic = rs.getString("pic");
urlhtml = rs.getString("url");
pic1 = rs.getString("pic1");
pic2 = rs.getString("pic2");
pic3 = rs.getString("pic3");
pic4 = rs.getString("pic4");
pic5 = rs.getString("pic5");
pic6 = rs.getString("pic6");
htmlname = rs.getString("filename");
miaoshu = rs.getString("miaoshu");
mname = rs.getString("mname");
//输出结果
System.out.println(title + "\t" + keywords);
MakeHtml(filePath,imagePath,disrPath,miaoshu,mname,title,keywords,descriptions
,pic,urlhtml,pic1,pic2,pic3,pic4,pic5,pic6,htmlname
);
PreparedStatement psql;
psql = con.prepareStatement("update movie set status = 2 where id = ?");
psql.setInt(1,rs.getInt("id"));
// psql.executeUpdate();
}
rs.close();
con.close();
} catch(ClassNotFoundException e) {
//数据库驱动类异常处理
System.out.println("Sorry,can`t find the Driver!");
e.printStackTrace();
} catch(SQLException e) {
//数据库连接失败异常处理
e.printStackTrace();
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}finally{
System.out.println("数据库数据成功获取!!");
}
// MakeHtml(filePath,imagePath,disrPath,fileName);
}
/**
* @Title: MakeHtml
* @Description: 创建html
* @param filePath 设定模板文件
* @param imagePath 需要显示图片的路径
* @param disrPath 生成html的存放路径
* @param fileName 生成html名字
* @return void 返回类型
* @throws
*/
public static void MakeHtml(String filePath,String imagePath,String disrPath,String miaoshu,String mname
,String title,String keywords,String descriptions
,String pic,String urlhtml,String pic1,String pic2,String pic3,String pic4,String pic5,String pic6,String htmlname){
try {
// String title = "<image src="+'"'+imagePath+'"'+"/>";
System.out.print(filePath);
String templateContent = "";
FileInputStream fileinputstream = new FileInputStream(filePath);// 读取模板文件
InputStreamReader read = new InputStreamReader(
fileinputstream, "gbk");
int lenght = fileinputstream.available();
char bytes[] = new char[lenght];
read.read(bytes);
//fileinputstream.read(bytes);
fileinputstream.close();
templateContent = new String(bytes);
System.out.print(templateContent);
templateContent = templateContent.replaceAll("###title###", title)
.replaceAll("###keywords###", keywords)
.replaceAll("###descriptions###", descriptions)
.replaceAll("###pic###", pic)
.replaceAll("###url###", urlhtml)
.replaceAll("###pic1###", pic1)
.replaceAll("###pic2###", pic2)
.replaceAll("###pic3###", pic3)
.replaceAll("###pic4###", pic4)
.replaceAll("###pic5###", pic5)
.replaceAll("###pic6###", pic6)
.replaceAll("###miaoshu###", miaoshu)
.replaceAll("###mname###", mname);
System.out.print(templateContent);
String fileame = htmlname + ".html";
fileame = disrPath+"/" + fileame;// 生成的html文件保存路径。
FileOutputStream fileoutputstream = new FileOutputStream(fileame);// 建立文件输出流
System.out.print("文件输出路径:");
System.out.print(fileame);
byte tag_bytes[] = templateContent.getBytes();
fileoutputstream.write(tag_bytes);
fileoutputstream.close();
} catch (Exception e) {
System.out.print(e.toString());
}
}
}
html.rar_html页面_java 静态模板_java 静态页面_java生成html_静态页面
版权申诉
166 浏览量
2022-09-23
19:11:37
上传
评论
收藏 10KB RAR 举报
局外狗
- 粉丝: 64
- 资源: 1万+
最新资源
- 珍藏多年的基于matlab实现潮流计算程序源代码集合,包含多个潮流计算程序.rar
- 使用FPGA实现串-并型乘法器
- 基于matlab实现针对基于双曲线定位的DV-Hop算法中误差误差出一种基于加权双曲线定位的DV-Hop改进算法.rar
- 基于matlab实现由遗传算法开发的整数规划,车辆调度问题.rar
- 电视家7.0(对电视配置要求高).apk
- 免费计算机毕业设计-基于JavaEE的医院病历管理系统设计与实现(包含论文+源码)
- 手机端 我的世界融合植物大战僵尸版.apk
- 植物大战僵尸 · 戴夫的老年生活 手机版.apk
- Runcraft · 我的世界跑酷游戏 手机端.apk
- pta题库答案c语言.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈