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

📄 saveedit.jsp

📁 LyNews凌云新闻系统
💻 JSP
字号:
<%
/*##################################################################**
**#  项目名称:LyNews『凌云新闻』                                  #**
**#                                                                #**
**#  程序开发: teddy 『星语凌』                                    #**
**#                                                                #**
**#  版权所有: 凌云创作室 (原流星电脑工作室)                       #**
**#                                                                #**
**#  主页地址: http://www.lybbs.com                                #**
**#            http://www.lybbs.net                                #**
**#  电邮地件: horseye@sina.com                                    #**
**#                                                                #**
**##################################################################*/
%>
<%@include file="config.jsp"%>
<%@include file="getsession.jsp"%>
<%@page contentType="text/html;charset=GBK"%>

<%
/**
*  Title  保存新闻
*  @author: teddy
*  Company: http://www.glsc.com.cn
*  Copyright: Copyright (c) 2003 - 2004
*  @version 1.0
*/
%>

<%
ParameterUtils.setCharacterEncoding(request);

Factory factory = Factory.getInstance();
UserFactory userFactory = factory.getUserFactory();
BoardFactory boardFactory = factory.getBoardFactory();

try{
  sessionUser = userFactory.checkUser(sessionUser);
}
catch(Exception e) {
  throw new Exception(e.getMessage());
}

String[] flag = {"<$title$>","<$date$>","<$author$>","<$from$>","<$content$>","<$editer$>","<$list$>","<$head$>"};

/**
*  获取基本信息
*/
String subject = ParameterUtils.getString(request,"subject");
String author = ParameterUtils.getString(request,"author");
String from = ParameterUtils.getString(request,"from");
int top = ParameterUtils.getInt(request,"top");
String content = ParameterUtils.getString(request,"content");
int boardID = ParameterUtils.getInt(request,"boardID");
int boardParentID=ParameterUtils.getInt(request,"boardParentID");

if(subject.equals(""))
  throw new Exception("请输入新闻标题。");
else if(content.equals(""))
  throw new Exception("请输入新闻内容。");
else if(top<0 || top>3)
  throw new Exception("新闻级别值不合法。");
if(author.equals(""))
  author="未知";
if(!from.equals(""))
  from = "摘自:"+from;

Iterator boardParentIterator=boardFactory.listParent();
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("<TD><a href=index.jsp>首 页</a></TD>");
while(boardParentIterator.hasNext()) {
  Board boardParentAll=(Board)boardParentIterator.next();
  stringBuffer.append("<TD><a href='../../../../catalog.jsp?boardParentID=");
  stringBuffer.append(boardParentAll.getID());
  stringBuffer.append("'>");
  stringBuffer.append(boardParentAll.getBoardName());
  stringBuffer.append("</a></TD>");
  }
String head=stringBuffer.toString();

Iterator boardIterator = boardFactory.list(boardParentID);
stringBuffer = new StringBuffer();
stringBuffer.append("<ul>");
while(boardIterator.hasNext()) {
  Board board = (Board)boardIterator.next();
  stringBuffer.append("<li><a class=list href='../../../../list.jsp?boardParentID=");
  stringBuffer.append(board.getParentID());
  stringBuffer.append("&boardID=");
  stringBuffer.append(board.getID());
  stringBuffer.append("'>");
  stringBuffer.append(board.getBoardName());
  stringBuffer.append("</a>");
}
stringBuffer.append("</ul>");
String list=stringBuffer.toString();

String filePath = "";
filePath = application.getRealPath("./template/news.template");

String templateContent;
try{
  templateContent = ReadTemplates.getTlpContent(filePath);
}
catch(ReadTemplateException e){
  throw new Exception(e.getMessage());
}


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());
templateContent = ReplaceAll.replace(templateContent,flag[6],list);
templateContent = ReplaceAll.replace(templateContent,flag[7],head);

// 根据时间得文件名与路径名
Calendar calendar = Calendar.getInstance();
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 e){
  throw new Exception("新闻发布失败。可能是目录不具备IO操作权限。请与管理员联系。");
}

News news = factory.getNews();
NewsFactory newsFactory = factory.getNewsFactory();

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

news.setBoardID(boardID);
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.setTop(top);
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>
<li><a href="edit.jsp?boardParentID=<%=boardParentID%>&boardID=<%=boardID%>">继续发布</a><br><br>
<li><a href="list.jsp?boardParentID=<%=boardParentID%>&boardID=<%=boardID%>">新闻管理</a>
</center>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -