?? change.jsp
字號:
<%@page contentType="text/html;charset=GBK"%>
<%@page import="net.ijsp.news.util.*,
net.ijsp.news.news.*,
java.util.*,
java.text.*,
java.sql.ResultSet,
net.ijsp.news.database.*"%>
<%
%>
<%
String[] flag = {"<$title$>","<$date$>","<$author$>","<$else$>","<$content$>","<$editer$>"};
String subject,author,content;
int id;
String dddd = "";
long dd =0;
String filePath = "";
filePath = application.getRealPath("./template/news.template");
String templateContent1;
try{
templateContent1 = ReadTemplates.getTlpContent(filePath);
}catch(ReadTemplateException e){
throw new Exception("<li>模板信息讀取失敗。請聯(lián)系系統(tǒng)管理員。");
}
DBConnect dbc = new DBConnect();
dbc.prepareStatement("SELECT * FROM books ");
ResultSet rs = dbc.executeQuery();
int iiii=0;
while(rs.next()) {
System.out.println(iiii++);
subject = rs.getString("BookName");
author = rs.getString("author");
content = rs.getString("Content");
id = rs.getInt("bookClass");
if(id==1)
id = 23;
else if(id==2)
id = 22;
else if(id==3)
id = 24;
else if(id==4)
id = 25;
else if(id==5)
id = 21;
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ParsePosition pos=new ParsePosition(0);
Date strtodate=formatter.parse(rs.getString("showDate"),pos);
if(author.equals(""))
author="未知";
//if(!from.equals(""))
String from = "";
//= "摘自:"+from;
String templateContent = ReplaceAll.replace(templateContent1,flag[0],subject);
templateContent = ReplaceAll.replace(templateContent,flag[1],GetDate.getStringDate());
templateContent = ReplaceAll.replace(templateContent,flag[2],author);
templateContent = ReplaceAll.replace(templateContent,flag[3],from);
templateContent = ReplaceAll.replace(templateContent,flag[4],content);
templateContent = ReplaceAll.replace(templateContent,flag[5],"yangtse");
// 根據(jù)時間得文件名與路徑名
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(strtodate.getTime());
String fileName = String.valueOf(calendar.getTimeInMillis()) +".shtml";
// 如果是linux系統(tǒng)請把 "\\" 改為 "/",謝謝
String pathName = application.getRealPath("./news")+"\\"+ calendar.get(Calendar.YEAR) +
"\\"+ (calendar.get(Calendar.MONTH)+1) +"\\"+ calendar.get(Calendar.DAY_OF_MONTH)+"\\";
/**
* 寫文件
*/
try{
WriteHtml.save(templateContent,pathName,fileName);
}catch(WriteFileException we){
throw new Exception("<li>新聞發(fā)布失敗。可能是目錄不具備IO操作權限。請與網(wǎng)管聯(lián)系。");
}
Factory factory = Factory.getInstance();
News news = factory.getNews();
NewsFactory newsFactory = factory.getNewsFactory();
/**
* 添加到數(shù)據(jù)庫
*/
news.setBoardID(id);
news.setEditer("yangtse");
news.setTitle(subject);
news.setNewsFile(calendar.get(Calendar.YEAR)+"/"+(calendar.get(Calendar.MONTH)+1)+"/"+ calendar.get(Calendar.DAY_OF_MONTH)+"/"+fileName);
news.setDate(calendar.getTimeInMillis());
news.setContent(templateContent);
newsFactory.add(news);
}
dbc.close();
%>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -