📄 managernews.java
字号:
package ch06;
import java.io.File;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Hashtable;
import java.util.Vector;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class managerNews {
public managerNews() throws Exception {
dbConn = new dbConn();
handle = new handle();
filter = new filter();
config = new config();
systemURL = config.systemURL + "/" + config.systemFolder + "/";
}
public void AddClick(HttpServletRequest httpservletrequest,
HttpServletResponse httpservletresponse, String s) throws Exception {
String s1 = handle.getString(httpservletrequest, "Nid");
if (handle.getCookie(httpservletrequest, "CookieNid") == null
|| !handle.getCookie(httpservletrequest, "CookieNid")
.equals(s1)) {
String s2 = "UPDATE " + s + " SET click = click + 1 WHERE id = "
+ s1;
dbConn.ExeUpdate(s2);
dbConn.CloseConn();
handle.setCookie(httpservletresponse, "CookieNid", s1, 300);
}
}
public void AddImgsInfo(String s, String s1,
HttpServletRequest httpservletrequest, HttpSession httpsession)
throws Exception {
int i = 0;
if (httpsession.getAttribute("ImgsName") != null) {
String s4 = handle
.GBK2ISO(httpservletrequest.getParameter("topic"));
try {
String s2 = "SELECT * FROM " + s + " WHERE topic = '" + s4
+ "' ORDER BY id DESC";
ResultSet resultset = dbConn.ExeQuery(s2);
resultset.next();
i = resultset.getInt("id");
} catch (SQLException sqlexception) {
System.err
.println("AddImgsInfo():" + sqlexception.getMessage());
}
Vector vector = (Vector) httpsession.getAttribute("ImgsName");
for (int j = 0; j < vector.size(); j++) {
String s5 = (String) vector.elementAt(j);
String s3 = "INSERT INTO " + s1 + "(info_id,img_name) VALUES("
+ i + ",'" + s5 + "')";
dbConn.ExeUpdate(s3);
}
dbConn.CloseConn();
httpsession.removeAttribute("ImgsName");
}
}
public void AddNews(String s, String s1, String s2,
HttpServletRequest httpservletrequest, HttpSession httpsession)
throws Exception {
String topic = handle.GBK2ISO(httpservletrequest.getParameter("topic"));
String content = handle.GBK2ISO(httpservletrequest.getParameter("content"));
content = filter.dealWithURLFilte(content);
String keywords = handle.GBK2ISO(httpservletrequest.getParameter("keywords"));
String source = handle.GBK2ISO(httpservletrequest.getParameter("source"));
String light = handle.getString(httpservletrequest, "light");
int i = handle.getInt(httpservletrequest, "pagination");
int type_id = handle.getInt(httpservletrequest, "type_id");
int content_type = handle.getInt(httpservletrequest, "content_type");
if (!checkStation(httpservletrequest, "127.0.0.1"))
throw new Exception("<font color=red size=2>请在127.0.0.1下使用</font>");
String paginationStr = "";
if (i == 0) {
if (httpsession.getAttribute("paginationStr") == null) {
paginationStr = "";
} else {
paginationStr = (String) httpsession.getAttribute("paginationStr");
httpsession.removeAttribute("paginationStr");
httpsession.removeAttribute("type_id");
httpsession.removeAttribute("source");
httpsession.removeAttribute("keywords");
httpsession.removeAttribute("topic");
}
} else if (httpsession.getAttribute("paginationStr") == null) {
long l = (new Date()).getTime();
paginationStr = String.valueOf(l);
httpsession.setAttribute("paginationStr", paginationStr);
httpsession.setAttribute("type_id", new Integer(type_id));
httpsession.setAttribute("source", handle.ISO2GBK(source));
httpsession.setAttribute("keywords", handle.ISO2GBK(keywords));
httpsession.setAttribute("topic", handle.ISO2GBK(topic));
} else {
paginationStr = (String) httpsession.getAttribute("paginationStr");
}
String sql = "INSERT INTO "
+ s
+ "(topic,content,content_type,keywords,source,type_id,pagination,date_time,light) " +
"VALUES(?,?,?,?,?,?,?,?,?)";
dbConn.getPreparedStatement(sql);
dbConn.setString(1, topic);
dbConn.setString(2, content);
dbConn.setInt(3, content_type);
dbConn.setString(4, keywords);
dbConn.setString(5, source);
dbConn.setInt(6, type_id);
dbConn.setString(7, paginationStr);
dbConn.setString(8, ch06.handle.getDateTime());
dbConn.setString(9, light);
dbConn.ExeUpdate();
AddImgsInfo(s, s1, httpservletrequest, httpsession);
dbConn.CloseConn();
}
public void AddType(HttpServletRequest httpservletrequest, String s)
throws Exception {
String s1 = handle.GBK2ISO(httpservletrequest.getParameter("title"));
String s2 = "INSERT INTO " + s + "(title) VALUES('" + s1 + "')";
dbConn.ExeUpdate(s2);
dbConn.CloseConn();
}
public Vector CheckImg(String s, int i) throws Exception {
Vector vector = new Vector();
try {
String s1 = "SELECT * FROM " + s + " WHERE info_id=" + i;
for (ResultSet resultset = dbConn.ExeQuery(s1); resultset.next(); vector
.addElement(resultset.getString("img_name")))
;
dbConn.CloseConn();
} catch (SQLException sqlexception) {
System.err.println("CheckImg():" + sqlexception.getMessage());
}
return vector;
}
public String[] CheckSplit(String s, String s1, String s2, String s3,
String s4) throws Exception {
String as[] = new String[4];
if (s1.equals("")) {
as[0] = s2;
as[1] = s3;
as[2] = s4;
as[3] = "nothing";
} else {
try {
String s5 = "SELECT * FROM " + s + " WHERE pagination = " + s1
+ " ORDER BY id ASC";
ResultSet resultset = dbConn.ExeQuery(s5);
resultset.next();
as[0] = resultset.getString("id");
as[1] = resultset.getString("topic");
as[2] = resultset.getString("date_time");
as[3] = resultset.getString("pagination");
dbConn.CloseConn();
} catch (SQLException sqlexception) {
System.err.println("CheckSplit():" + sqlexception.getMessage());
}
}
return as;
}
public String ConvertChar(String s) {
String s1 = handle.Replace("<", "<", s);
s1 = handle.Replace(">", ">", s1);
s1 = handle.Replace("<center>", "<center>", s1);
s1 = handle.Replace("</center>", "</center>", s1);
s1 = handle.Replace("<left>", "<left>", s1);
s1 = handle.Replace("</left>", "</left>", s1);
s1 = handle.Replace("<right>", "<right>", s1);
s1 = handle.Replace("</right>", "</right>", s1);
s1 = handle.Replace("\n", "<br>", s1);
s1 = handle.Replace(" ", " ", s1);
return s1;
}
public String DealWithContent(HttpServletRequest httpservletrequest,
HttpSession httpsession, String s, String s1) {
int i = handle.getInt(httpservletrequest, "content_type");
if (httpsession.getAttribute("ImgsName") != null) {
Vector vector = (Vector) httpsession.getAttribute("ImgsName");
for (int j = 0; j < vector.size(); j++) {
String s2 = (String) vector.elementAt(j);
s = handle.Replace("<left>[" + s2 + "]</left>", "<img src="
+ s1 + "/" + s2 + " align=left border=0>", s);
s = handle.Replace("<right>[" + s2 + "]</right>", "<img src="
+ s1 + "/" + s2 + " align=right border=0>", s);
s = handle.Replace("[" + s2 + "]", "<img src=" + s1 + "/" + s2
+ " border=0>", s);
}
}
return s;
}
public void DelNews(HttpServletRequest httpservletrequest, String s,
String s1, String s2) throws Exception {
String s4 = "";
int i = handle.getInt(httpservletrequest, "Nid");
try {
s4 = "SELECT * FROM " + s1 + " WHERE info_id=" + i;
for (ResultSet resultset = dbConn.ExeQuery(s4); resultset.next(); handle
.Del(httpservletrequest, s2 + "\\"
+ resultset.getString("img_name")))
;
s4 = "SELECT * FROM " + s + " WHERE id=" + i;
ResultSet resultset1 = dbConn.ExeQuery(s4);
resultset1.next();
String s3 = resultset1.getString("date_time");
handle.Del(httpservletrequest, config.htmlFolder + "/"
+ handle.Convert2Path(resultset1.getInt("id"), s3));
} catch (SQLException sqlexception) {
System.err.println("DelNews1():" + sqlexception.getMessage());
}
s4 = "DELETE FROM " + s + " WHERE id = " + i;
dbConn.ExeUpdate(s4);
s4 = "DELETE FROM " + s1 + " WHERE info_id=" + i;
dbConn.ExeUpdate(s4);
dbConn.CloseConn();
}
public void DelNews(HttpServletRequest httpservletrequest, String s,
String s1, String s2, int i) throws Exception {
String s3 = "";
try {
s3 = "SELECT * FROM " + s1 + " WHERE info_id=" + i;
for (ResultSet resultset = dbConn.ExeQuery(s3); resultset.next(); handle
.Del(httpservletrequest, s2 + "\\"
+ resultset.getString("img_name")))
;
s3 = "SELECT * FROM " + s + " WHERE id=" + i;
ResultSet resultset1 = dbConn.ExeQuery(s3);
resultset1.next();
String s4 = resultset1.getString("date_time");
handle.Del(httpservletrequest, config.htmlFolder + "/"
+ handle.Convert2Path(resultset1.getInt("id"), s4));
} catch (SQLException sqlexception) {
System.err.println("DelNews2():" + sqlexception.getMessage());
}
s3 = "DELETE FROM " + s1 + " WHERE info_id=" + i;
dbConn.ExeUpdate(s3);
s3 = "DELETE FROM " + s + " WHERE id = " + i;
dbConn.ExeUpdate(s3);
}
public void DelType(HttpServletRequest httpservletrequest, String s,
String s1, String s2, String s3, String s4, String s5)
throws Exception {
int i = handle.getInt(httpservletrequest, "type_id");
String s6 = "DELETE FROM " + s + " WHERE id=" + i;
dbConn.ExeUpdate(s6);
s6 = "DELETE FROM " + s4 + " WHERE id=" + i;
dbConn.ExeUpdate(s6);
s6 = "DELETE FROM " + s3 + " WHERE tid=" + i;
dbConn.ExeUpdate(s6);
try {
String s7 = "SELECT * FROM " + s1 + " WHERE type_id=" + i;
for (ResultSet resultset = dbConn.ExeQuery(s7); resultset.next(); DelNews(
httpservletrequest, s1, s2, s5, resultset.getInt("id")))
;
dbConn.CloseConn();
} catch (SQLException sqlexception) {
System.err.println("DelType():" + sqlexception.getMessage());
}
}
public newsBean DetailNews(String s, String s1, String s2,
HttpServletRequest httpservletrequest,
HttpServletResponse httpservletresponse, HttpSession httpsession)
throws Exception {
String s5 = "";
ResultSet resultset = null;
int i = handle.getInt(httpservletrequest, "Nid");
int j = 0;
newsBean newsbean = new newsBean();
try {
String s3 = "SELECT * FROM " + s + " WHERE id = " + i;
resultset = dbConn.ExeQuery(s3);
resultset.next();
String s6 = resultset.getString("content");
newsbean.setTopic(resultset.getString("topic"));
newsbean.setId(resultset.getInt("id"));
newsbean.setTypeId(resultset.getInt("type_id"));
newsbean.setKeywords(resultset.getString("keywords"));
newsbean.setContent(s6);
newsbean.setDateTime(handle.Split(" ", resultset
.getString("date_time"))[0]);
newsbean.setSource(resultset.getString("source"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -