⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 change.jsp

📁 新闻发布 由于程序采用了静态的HTML作为新闻存储的格式
💻 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>模板信息读取失败。请联系系统管理员。");
}

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");

// 根据时间得文件名与路径名
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(strtodate.getTime());
String fileName = String.valueOf(calendar.getTimeInMillis()) +".shtml";
// 如果是linux系统请把 "\\" 改为 "/",谢谢
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>新闻发布失败。可能是目录不具备IO操作权限。请与网管联系。");
}
Factory factory = Factory.getInstance();
News news = factory.getNews();
NewsFactory newsFactory = factory.getNewsFactory();

/**
* 添加到数据库
*/

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 + -