📄 saveedit.jsp
字号:
<%@ page language="java" contentType="text/html; charset=gbk" %>
<%@page import="net.ijsp.news.util.*,
net.ijsp.news.news.*,
java.util.*"%>
<%@include file="getsession.jsp"%>
<%
String cBytes = "GBK";
request.setCharacterEncoding(cBytes);
//对用户是否登陆检测
Factory factory = Factory.getInstance();
UserFactory userFactory = factory.getUserFactory();
try{
sessionUser = userFactory.chkUser(sessionUser);
}catch(UserNotFoundException ue) {
String str = new String("你的用户名不存在。请重新确认!");
request.setAttribute("err",str);
%>
<jsp:forward page="error.jsp"/>
<%
}catch(UserPasswordException u) {
String str = new String("您输入的用户名或密码错误。请重新确认!");
request.setAttribute("err",str);
%>
<jsp:forward page="error.jsp"/>
<%
}
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("")){
String str = new String("标题不能为空!");
request.setAttribute("err",str);
%>
<jsp:forward page="error.jsp"/>
<%
}
if(content.equals("")){
String str = new String("内容不能为空!");
request.setAttribute("err",str);
%>
<jsp:forward page="error.jsp"/>
<%
}
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()) +".html";
// 如果是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){
String str = new String("新闻发布失败。可能是目录不具备IO操作权限。请与网管联系。");
request.setAttribute("err",str);
}
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 + -