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

📄 managernews.java

📁 用jsp实现的大型商城源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	public void AddImgsInfo(String tb_news_info,String tb_news_imgs,HttpServletRequest request,HttpSession session) throws Exception {
		String SqlStr;
		ResultSet rs;
		int id = 0;
		Vector VImgsName;

		if (session.getAttribute("ImgsName") != null) {
			//--- 取得刚刚插入新闻的ID ---
			String topic = handle.GBK2ISO(request.getParameter("topic"));
			try {
				SqlStr = "SELECT * FROM " + tb_news_info + " WHERE topic = '" + topic + "' ORDER BY id DESC";
				rs = dbconn.ExeQuery(SqlStr);
				rs.next();
				id = rs.getInt("id");
			}
			catch (SQLException ex) {
				System.err.println("aq.executeQuery:"+ex.getMessage());
			}
			
			VImgsName = (Vector)session.getAttribute("ImgsName");
			for (int i=0; i<VImgsName.size(); i++) {
				String img_name = (String)VImgsName.elementAt(i);
				SqlStr = "INSERT INTO " + tb_news_imgs + "(info_id,img_name) VALUES(" + id + ",'" + img_name + "')";
				dbconn.ExeUpdate(SqlStr);
			}
		dbconn.CloseConn();
		session.removeAttribute("ImgsName");
		}
	}

	//--- 最新n条新闻 ---
	public Hashtable TopNNews(String tb_news_info,String tb_news_type,int n) throws Exception {
		String SqlStr,SqlStr2,pre_topic="";
		String path[] = new String[n];
		String topic[] = new String[n];
		String date_time[] = new String[n];
		String type[] = new String[n];
		Hashtable HashResult = new Hashtable();
		ResultSet rs,rs2;

		try {
			SqlStr = "SELECT * FROM " + tb_news_info + " WHERE type_id != 9 ORDER BY id DESC";
			rs = dbconn.ExeQuery(SqlStr);
			int i = 0;
			while (rs.next()) {
				if (i == n) break;
				String ArrayResult[] = CheckSplit(tb_news_info,rs.getString("pagination"),rs.getString("id"),rs.getString("topic"),rs.getString("date_time"));		//--- 处理分页 ---
				if (ArrayResult[1].equals(pre_topic)) continue;
				path[i] = handle.Convert2Path(Integer.parseInt(ArrayResult[0]),ArrayResult[2]);
				topic[i] = ArrayResult[1];
				pre_topic = topic[i];
				date_time[i] = ArrayResult[2];
				
				SqlStr2 = "SELECT * FROM " + tb_news_type + " WHERE id=" + rs.getInt("type_id");
				rs2 = dbconn.ExeQuery(SqlStr2);
				rs2.next();
				type[i] = rs2.getString("title");
				i++;
			}
			dbconn.CloseConn();
		}
		catch (SQLException ex) {
			System.err.println("aq.executeQuery:"+ex.getMessage());
		}

		HashResult.put("path",path);
		HashResult.put("topic",topic);
		HashResult.put("date_time",date_time);
		HashResult.put("type",type);

		return(HashResult);
	}

	//--- 检查新闻是否分页并进行分页处理 ---
	public String[] CheckSplit(String tb_news_info,String pagination,String id,String topic,String date_time) throws Exception {
		String ArrayResult[] = new String[4];
		ResultSet rs;

		if (pagination.equals("")) {
			ArrayResult[0] = id;
			ArrayResult[1] = topic;
			ArrayResult[2] = date_time;
			ArrayResult[3] = "nothing";
		}
		else {
			try {
				String SqlStr = "SELECT * FROM " + tb_news_info + " WHERE pagination = " + pagination + " ORDER BY id ASC";
				rs = dbconn.ExeQuery(SqlStr);
				rs.next();
				ArrayResult[0] = rs.getString("id");
				ArrayResult[1] = rs.getString("topic");
				ArrayResult[2] = rs.getString("date_time");
				ArrayResult[3] = rs.getString("pagination");
				dbconn.CloseConn();
			}
			catch (SQLException ex) {
				System.err.println("aq.executeQuery:"+ex.getMessage());
			}
		}

		return(ArrayResult);
	}

	//--- 商城热讯 ---
	public Hashtable ReXun(String tb_news_info,int n) throws Exception {
		String SqlStr;
		String id[] = new String[n];
		String topic[] = new String[n];
		Hashtable HashResult = new Hashtable();
		ResultSet rs;

		try {
			SqlStr = "SELECT * FROM " + tb_news_info + " WHERE type_id = 9 ORDER BY id DESC";
			rs = dbconn.ExeQuery(SqlStr);
			for (int i=0; i<n; i++) {
				if (!rs.next()) break;
				id[i] = rs.getString("id");
				topic[i] = rs.getString("topic");
			}
			dbconn.CloseConn();
		}
		catch (SQLException ex) {
			System.err.println("aq.executeQuery:"+ex.getMessage());
		}
		HashResult.put("id",id);
		HashResult.put("topic",topic);

		return(HashResult);
	}

	//--- 详细新闻内容 ---
	public Hashtable DetailNews(String tb_news_info,HttpServletRequest request,HttpServletResponse response) throws Exception {
		String SqlStr,SplitNum="";
		ResultSet rs=null;
		Hashtable HashResult = new Hashtable();
		int Nid = handle.getInt(request,"Nid");
		int i=0;

		AddClick(request,response,tb_news_info);

		try {
			SqlStr = "SELECT * FROM " + tb_news_info + " WHERE id = " + Nid;
			rs = dbconn.ExeQuery(SqlStr);
			rs.next();
			HashResult.put("topic",rs.getString("topic"));
			HashResult.put("content",rs.getString("content"));
			HashResult.put("date_time",handle.Split(" ",rs.getString("date_time"))[0]);
			HashResult.put("click",rs.getString("click"));
			HashResult.put("source",rs.getString("source"));
			HashResult.put("type_id",rs.getString("type_id"));
			HashResult.put("content_type",rs.getString("content_type"));
			HashResult.put("keywords",rs.getString("keywords"));
			HashResult.put("original_content",rs.getString("original_content"));
		}
		catch (SQLException ex) {
			System.err.println("aq.executeQuery:"+ex.getMessage());
		}
		
		//--- 如果有分页,则分页显示 ---
		try {
			SqlStr = "SELECT * FROM " + tb_news_info + " WHERE pagination = " + rs.getString("pagination") + " ORDER BY id ASC";
			rs = dbconn.ExeQuery(SqlStr);
			while (rs.next()) {
				i++;
				String path = handle.Convert2Path(rs.getInt("id"),rs.getString("date_time"));
				if (Nid == rs.getInt("id")) SplitNum += "[<font color=red>" + i + "</font>] ";
				else SplitNum += "[<a href=../" + path + ">" + i + "</a>] ";
			}
		}
		catch (SQLException ex) {
			System.err.println("aq.executeQuery:"+ex.getMessage());
		}
		HashResult.put("SplitNum",SplitNum);

		dbconn.CloseConn();
		return(HashResult);
	}

	//--- 增加阅读数 ---
	public void AddClick(HttpServletRequest request,HttpServletResponse response,String tb_news_info) throws Exception {
		String Nid = handle.getString(request,"Nid");

		if (handle.getCookie(request,"myshopNid") == null || !handle.getCookie(request,"myshopNid").equals(Nid)) {
			String SqlStr = "UPDATE " + tb_news_info + " SET click = click + 1 WHERE id = " + Nid;
			dbconn.ExeUpdate(SqlStr);
			dbconn.CloseConn();
			handle.setCookie(response,"myshopNid",Nid,60*5);
		}
	}

	//--- 显示相关新闻 ---
	public Hashtable RelationNews(String tb_news_info,HttpServletRequest request,int n) throws Exception {
		String SqlStr;
		String current_topic="",current_pagination="",keywords="",CondictionStr="",pre_topic="";
		String path[] = new String[n];
		String topic[] = new String[n];
		String date_time[] = new String[n];
		ResultSet rs;
		Hashtable HashResult = new Hashtable();
		int Nid = handle.getInt(request,"Nid");
		int i,j=0;
		
		try {
			SqlStr = "SELECT * FROM " + tb_news_info + " WHERE id=" + Nid;
			rs = dbconn.ExeQuery(SqlStr);
			rs.next();
			current_topic = rs.getString("topic");
			current_pagination = rs.getString("pagination");
			keywords = rs.getString("keywords");
			dbconn.CloseConn();
		}
		catch (SQLException ex) {
			System.err.println("aq.executeQuery:"+ex.getMessage());
		}

		//--- 重组条件语句 ---
		keywords = handle.GBK2ISO(keywords);				//不转换中文,得不到正确的搜索结果!!
		String ArrayKeywords[] = handle.Split(",",keywords);
		if (ArrayKeywords.length == 1) CondictionStr += "keywords LIKE '%" + ArrayKeywords[0] + "%'";
		else {
			for (i=0; i<ArrayKeywords.length-1; i++) CondictionStr += "keywords LIKE '%" + ArrayKeywords[i] + "%' OR ";
			CondictionStr += "keywords LIKE '%" + ArrayKeywords[i] + "%'";
		}

		try {
			SqlStr = "SELECT * FROM " + tb_news_info + " WHERE "+ CondictionStr + " ORDER BY id DESC";
			rs = dbconn.ExeQuery(SqlStr);
			while (rs.next()) {
				if (j == n) break;
				String ArrayResult[] = CheckSplit(tb_news_info,rs.getString("pagination"),rs.getString("id"),rs.getString("topic"),rs.getString("date_time"));		//--- 处理分页 ---
				if (ArrayResult[1].equals(pre_topic) || ArrayResult[1].equals(current_topic) || ArrayResult[3].equals(current_pagination)) continue;
				//path[j] = handle.Convert2Path(Integer.parseInt(ArrayResult[0]),ArrayResult[2]);
				path[j] = ArrayResult[0];
				topic[j] = ArrayResult[1];
				pre_topic = topic[j];
				date_time[j] = handle.Split(" ",ArrayResult[2])[0];
				j++;
			}
			dbconn.CloseConn();
		}
		catch (SQLException ex) {
			System.err.println("aq.executeQuery:"+ex.getMessage());
		}
		HashResult.put("path",path);
		HashResult.put("topic",topic);
		HashResult.put("date_time",date_time);
		return(HashResult);
	}

	//--- 添加新栏目 ---
	public void AddType(HttpServletRequest request,String tb_news_type) throws Exception {
		String title = handle.GBK2ISO(request.getParameter("title"));

		String SqlStr = "INSERT INTO " + tb_news_type + "(title,date_time) VALUES('" + title + "',sysdate())";
		dbconn.ExeUpdate(SqlStr);
		dbconn.CloseConn();
	}

	//--- 修改栏目 ---
	public void ModType(HttpServletRequest request,String tb_news_type) throws Exception {
		String title = handle.GBK2ISO(request.getParameter("title"));
		int type_id = handle.getInt(request,"type_id");

		String SqlStr = "UPDATE " + tb_news_type + " SET title='" + title + "' WHERE id=" + type_id;
		dbconn.ExeUpdate(SqlStr);
		dbconn.CloseConn();
	}

⌨️ 快捷键说明

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