📄 saveedit.jsp
字号:
<%@page contentType="text/html;charset=GBK"%>
<%@page import="net.ijsp.news.util.*,
net.ijsp.news.news.*,
java.util.*"%>
<%
/**
* Title 保存新闻
* @author: ccjsmile
* Company: http://www.ijsp.net
* Copyright: Copyright (c) 2003
* @version 1.0 beta
*/
%>
<%@include file="getsession.jsp"%>
<%
Factory factory = Factory.getInstance();
UserFactory userFactory = factory.getUserFactory();
try{
sessionUser = userFactory.chkUser(sessionUser);
}catch(UserNotFoundException ue) {
throw new Exception("<li>您正在尝试进行非法的操作。");
}catch(UserPasswordException u) {
throw new Exception("<li>您输入的用户名或密码错误。");
}
String[] flag = {"<$title$>","<$date$>","<$author$>","<$else$>","<$content$>","<$editer$>"};
/**
* 获取基本信息
*/
String subject = ParamUtils.getString(request,"subject","");
String author = ParamUtils.getString(request,"author","");
String from = ParamUtils.getString(request,"from","");
String content = ParamUtils.getString(request,"content","");
int id = ParamUtils.getInt(request,"id",0);
if(subject.equals(""))
throw new Exception("<li>请输入新闻标题。");
if(content.equals(""))
throw new Exception("<li>请输入新闻内容。");
if(author.equals(""))
author="未知";
if(!from.equals(""))
from = "摘自:"+from;
String filePath = "";
filePath = application.getRealPath("./tech/template/news.template");
String templateContent;
try{
templateContent = ReadTemplates.getTlpContent(filePath);
}catch(ReadTemplateException e){
throw new Exception("<li>模板信息读取失败。请联系系统管理员。");
}
templateContent = ReplaceAll.replace(templateContent,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],sessionUser.getUsername());
// 根据时间得文件名与路径名
Calendar calendar = Calendar.getInstance();
String fileName = String.valueOf(calendar.getTimeInMillis()) +".shtml";
// 如果是linux系统请把 "\\" 改为 "/",谢谢
String pathName = application.getRealPath("./tech/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操作权限。请与网管联系。");
}
News news = factory.getNews();
NewsFactory newsFactory = factory.getNewsFactory();
/**
* 添加到数据库
*/
news.setBoardID(id);
news.setEditer(sessionUser.getUsername());
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);
%>
<html>
<title>文章发布成功</title>
<link rel="stylesheet" href="../inc/admin.css" type="text/css">
<BODY leftmargin="0" bottommargin="0" rightmargin="0" topmargin="0" marginheight="0" marginwidth="0" bgcolor="#DDEEFF">
<br>
<center>文章发布成功。<br><br>
<a href="edit.jsp?id=<%=id%>">继续发布</a><br><br>
<a href="list.jsp?id=<%=id%>">新闻管理</a>
</center>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -