Java项目:SSH新闻资讯网站管理系统

作者主页:夜未央5788

 简介:Java领域优质创作者、Java项目、学习资料、技术互助

文末获取源码

项目介绍

该系统分成两个项目,前台项目与后台项目,需要分别运行;
后台管理员角色包含以下功能:
管理员登录,新闻专题类别管理,友情链接管理,广告管理,新闻列表管理,管理员管理,信息修改等功能。

前台用户角色包含以下功能:

用户首页,查看某一个新闻,用户登录注册,查看个人信息,评论新闻,查看某一类型的新闻,群聊交友等功能。

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 
5.数据库:MySql 5.7版本;

6.是否Maven项目:否;

技术栈

1. 后端:mysql+Spring+Struts+Hibernate

2. 前端:JSP+CSS+JavaScript+bootstrap+jquery+echarts

使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;

2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;

若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;

3. 将项目中config/jdbc.properties配置文件中的数据库配置改为自己的配置;

4. 运行项目,在浏览器中输入http://localhost:8080/ 登录

运行截图

前台界面

 

 

 

 

后台界面 

 

 

 

 

 

 

 

相关代码 

AdvertisementAction

package com.jssf.newsClient.action;


import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Date;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.jssf.newsClient.model.Advertisement;
import com.jssf.newsClient.service.AdvertisementService;
import com.jssf.newsClient.utils.Pager;
import com.jssf.newsClient.utils.UUIDUtils;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import net.sf.json.JSONArray;
@Controller("advertisementAction")
@Scope("prototype")
public class AdvertisementAction  extends ActionSupport implements ModelDriven<Advertisement>{
	//========================图片上传
	private File file;
	private String fileFileName;
	private String fileContentType;
    
    
   public File getFile() {
		return file;
	}
	public void setFile(File file) {
		this.file = file;
	}
	public String getFileFileName() {
		return fileFileName;
	}
	public void setFileFileName(String fileFileName) {
		this.fileFileName = fileFileName;
	}
	public String getFileContentType() {
		return fileContentType;
	}
	public void setFileContentType(String fileContentType) {
		this.fileContentType = fileContentType;
	}
private Advertisement advertisement;
	public Advertisement getModel() {
		if(advertisement==null) advertisement = new Advertisement();
		return advertisement;
	}
	@Autowired
	private AdvertisementService advertisementService;

	
	/**
	 * @return
	 */
	public String advertisement(){
		Pager<Advertisement> pagers = advertisementService.list(advertisement);
		ActionContext.getContext().put("pagers", pagers);
		return SUCCESS;
		
	}
    /**
     * 跳转添加页面
     * @return
     */
	public String addAdvertisement(){
	//	  ActionContext.getContext().put("path", null);
		return SUCCESS;
	}
	/**
	 * 添加
	 * @return
	 * @throws IOException 
	 */
    public String advertisementAdd() throws IOException{
    	advertisement.setCreateTime(new Date());
    	advertisementService.add(advertisement);
    	ActionContext.getContext().put("url", "/advertisement_advertisement.do");
		return "redirect";
    }
    
    /**
     * 
     * @return
     */
	public String Edit(){
		Advertisement Advertisements = null;
		if(advertisement.getId()!=0){
			Advertisements =	advertisementService.getById(advertisement.getId());
		}else{
			Object object = ActionContext.getContext().get("id");
			Advertisements =	advertisementService.getById(Integer.parseInt(object.toString()));
		}
		
		ActionContext.getContext().put("advertisement", Advertisements);
		return SUCCESS;
		
	}
	
	
	public String  editAdvertisement() throws IOException{
		HttpServletResponse resp = ServletActionContext.getResponse();
		resp.setContentType("application/json;charset=UTF-8");
		PrintWriter out = null;
		advertisementService.updateInfo(advertisement);
		ActionContext.getContext().put("url", "/advertisement_advertisement.do");
		return "redirect";
		
	}
    
    
    public String delAdvertisement(){
    	advertisementService.deleteInfo(advertisement.getId());
    	ActionContext.getContext().put("url", "/advertisement_advertisement.do");
		return "redirect";
    }
    
    /**
     * 图片上传
     * @return
     * @throws Exception
     */
	public String fileUpload() throws Exception{
		
		HttpSession session =	ServletActionContext.getRequest().getSession();
			int userId = Integer.parseInt( session.getAttribute("userId").toString());
			String root  = "D:/my/upload";
		        InputStream is = new FileInputStream(file);
		        fileFileName = UUIDUtils.create()+fileFileName;
		        OutputStream os = new FileOutputStream(new File(root, fileFileName));
		        System.out.println("fileFileName: " + fileFileName);
		        byte[] buffer = new byte[500];
		        int length = 0;
		        
		        while(-1 != (length = is.read(buffer, 0, buffer.length)))
		        {
		            os.write(buffer);
		        }
		        os.close();
		        is.close();
		        advertisement.setHrefs("\\upload\\"+fileFileName);
		      //  advertisementService.add(advertisement);
		        ActionContext.getContext().put("url", "advertisement_addAdvertisement");
		        ActionContext.getContext().put("path", "\\upload\\"+fileFileName);
		        return "chain";
	}
	 /**
     * 图片上传
     * @return
     * @throws Exception
     */
	public String fileUpload2() throws Exception{
		
		HttpSession session =	ServletActionContext.getRequest().getSession();
			int userId = Integer.parseInt( session.getAttribute("userId").toString());
			String root  = "D:/my/upload";
		        InputStream is = new FileInputStream(file);
		        fileFileName = UUIDUtils.create()+fileFileName;
		        OutputStream os = new FileOutputStream(new File(root, fileFileName));
		        System.out.println("fileFileName: " + fileFileName);
		        byte[] buffer = new byte[500];
		        int length = 0;
		        
		        while(-1 != (length = is.read(buffer, 0, buffer.length)))
		        {
		            os.write(buffer);
		        }
		        os.close();
		        is.close();
		        advertisement.setHrefs("\\upload\\"+fileFileName);
		      //  advertisementService.add(advertisement);
		        ActionContext.getContext().put("url", "advertisement_Edit");
		        ActionContext.getContext().put("id", advertisement.getId());
		        ActionContext.getContext().put("path", "\\upload\\"+fileFileName);
		        return "chain";
	}
}

LoginAction

package com.jssf.newsClient.action;
/**
 * 和登陆有关的都在这里
 */

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.jssf.newsClient.model.Extension;
import com.jssf.newsClient.model.Special;
import com.jssf.newsClient.model.User;
import com.jssf.newsClient.service.AdvertisementService;
import com.jssf.newsClient.service.ExtensionService;
import com.jssf.newsClient.service.NewsService;
import com.jssf.newsClient.service.SpecialService;
import com.jssf.newsClient.service.UserService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Controller("loginAction")
@Scope("prototype")
public class LoginAction extends ActionSupport implements ModelDriven<User>{
	private User user;
	@Autowired
	private UserService userService;
	private int otherId;
	@Autowired
    private ExtensionService extensionService;
	@Autowired
    private SpecialService specialService;
	@Autowired
    private NewsService newsService;
	@Autowired
	private AdvertisementService advertisementService;
	@Override
	public User getModel() {
		if(user==null) user = new User();
		return user;
	}
	//首页
	public String index(){
		return "success";
	}
	//登陆页面
	public String login() {
		//1查询合作站点以及友情链接
				List<Extension> es = extensionService.findAll();
				ActionContext.getContext().put("es", es);
				//2专题
				List<Special> ss = specialService.findAll();
				ActionContext.getContext().put("ss", ss);
		return "success";
	}
   //注册页面
	public void register() throws IOException {
		HttpServletResponse resp = ServletActionContext.getResponse();
		resp.setContentType("application/json;charset=UTF-8");
		PrintWriter out = null;
		JSONObject js = new JSONObject();
		user.setCreateTime(new Date());
		User u = userService.isregister(user);
		if(u != null){
			js.put("message", "用户名已存在!");
		}else{
			userService.add(user);
			js.put("message", "注册成功!");
		}
		out = resp.getWriter();
		 out.write(js.toString());
	}
   //退出
	public String tuichu() {
		ActionContext ac = ActionContext.getContext();
		Map session = ac.getSession();
		session.remove("userName");
		session.remove("userId");
		//1查询合作站点以及友情链接
		List<Extension> es = extensionService.findAll();
		ActionContext.getContext().put("es", es);
		//2专题
		List<Special> ss = specialService.findAll();
		ActionContext.getContext().put("ss", ss);
		return "login";
	}
}

ManageAction

package com.jssf.newsClient.action;


import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.github.abel533.echarts.axis.CategoryAxis;
import com.github.abel533.echarts.axis.ValueAxis;
import com.github.abel533.echarts.code.Trigger;
import com.github.abel533.echarts.data.PieData;
import com.github.abel533.echarts.json.GsonOption;
import com.github.abel533.echarts.series.Bar;
import com.github.abel533.echarts.series.Pie;
import com.jssf.newsClient.model.Manage;
import com.jssf.newsClient.model.User;
import com.jssf.newsClient.service.ManageService;
import com.jssf.newsClient.service.MessageService;
import com.jssf.newsClient.service.UserService;
import com.jssf.newsClient.utils.Pager;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import net.sf.json.JSONArray;
@Controller("manageAction")
@Scope("prototype")
public class ManageAction extends ActionSupport implements ModelDriven<Manage>{
   private Manage manage;
   @Autowired
	private UserService userService;
    @Autowired
   private ManageService manageService;
    @Autowired
	private MessageService messageService;
    private int userId;
    private String userName;
    private int sayId;
    
    
    public int getSayId() {
		return sayId;
	}
	public void setSayId(int sayId) {
		this.sayId = sayId;
	}

	private File file;
    
    public File getFile() {
		return file;
	}
	public void setFile(File file) {
		this.file = file;
	}
	public String getFileFileName() {
		return fileFileName;
	}
	public void setFileFileName(String fileFileName) {
		this.fileFileName = fileFileName;
	}
	public String getFileContentType() {
		return fileContentType;
	}
	public void setFileContentType(String fileContentType) {
		this.fileContentType = fileContentType;
	}

	//提交过来的file的名字
    private String fileFileName;
    
    //提交过来的file的MIME类型
    private String fileContentType;
	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	@Override
	public Manage getModel() {
		if(manage==null) manage = new Manage();
		return manage;
	}
   
	/**
	 * 登陆以后进入首页
	 * @return
	 */
	public String index(){
		Manage ma =	manageService.login(manage);
		if(ma == null){
			return "login";
		}
		HttpSession session =	ServletActionContext.getRequest().getSession();
		session.setAttribute("userName", ma.getName());
		session.setAttribute("userId", ma.getId());
	    return SUCCESS;
	}
	
	/**
	 * 获取用户列表
	 * @return
	 */
	public String userList(){
	Pager<User>	pagers = userService.listAll(userName);
	//这里需要对等级进行遍历
	/*List<Grade> list = gradeService.list();
	if(pagers != null && pagers.getDatas() != null && pagers.getDatas().size()>0){
		for(User u : pagers.getDatas()){
			//对这里的人 进行遍历
			for(Grade g: list){
				if(u.getJifen()>=g.getStartMin() && u.getJifen() <=g.getEndMax()){
					u.setDengji(g.getName());
				}
			}
		}
	}*/
	ActionContext.getContext().put("pagers", pagers);
	ActionContext.getContext().put("userName1", userName);
	return SUCCESS;
	}
	
	/**
	 * 根据用户id查询所有图片
	 * @return
	 */
	/*public String userPhotos(){
		Pager<SayMood>	pagers = sayMoodService.findAllphotosById(userId);
		ActionContext.getContext().put("pagers", pagers);
		return SUCCESS;
	}
	*/
	/**
	 * 删除照片
	 * @return
	 */
	/*public String delsay(){
		 sayMoodService.del(sayId);
		ActionContext.getContext().put("url", "/manage_userPhotos.do");
		return "redirect";
	}*/
	//删除用户
	public String delUse(){
		userService.delUse(userId);
		ActionContext.getContext().put("url", "/manage_userList.do");
		return "redirect";
	}
	
	//经警告用户
	
	public String jinggao(){
		messageService.updatejinggao(userId);
		ActionContext.getContext().put("url", "/manage_userList.do");
		return "redirect";
	}
	/**
	 * 图片上传
	 * @return
	 * @throws Exception
	 */
	/*public String fileUpload() throws Exception{
		HttpSession session =	ServletActionContext.getRequest().getSession();
		if(session.getAttribute("userId") != null){
			int userId = Integer.parseInt( session.getAttribute("userId").toString());
			
			 String root = ServletActionContext.getServletContext().getRealPath("/")+"upload";
			//String root = ServletActionContext.getServletContext().getRealPath("upload"); 
			//String root = ServletActionContext.getRequest().getContextPath()+"/"+"upload";
		        InputStream is = new FileInputStream(file);
		        fileFileName = UUIDUtils.create()+fileFileName;
		        OutputStream os = new FileOutputStream(new File(root, fileFileName));
		        System.out.println("fileFileName: " + fileFileName);
		        System.out.println("file: " + file.getName());
		        System.out.println("file: " + file.getPath());
		        byte[] buffer = new byte[500];
		        int length = 0;
		        
		        while(-1 != (length = is.read(buffer, 0, buffer.length)))
		        {
		            os.write(buffer);
		        }
		        os.close();
		        is.close();
		        //接下来存到说说表中
		        SayMood sayMood = new SayMood();
		        sayMood.setContent("\\upload\\"+fileFileName);
		        sayMood.setCreateTime(new Date());
		        sayMood.setDzs(0);
		        sayMood.setIsDelete(2);
		        sayMood.setType(2);
		        User u = userService.getUser(userId);
		        sayMood.setSayUser(u);
		        sayMoodService.save(sayMood);
		        *//**
		         * 积分规则还没有做。上传图片需要加积分
		         *//*
		        //上传完毕,跳转列表action
		        ActionContext.getContext().put("url", "/user_homePage.do");
		        return "redirect";
		}else{
			return "login";
		}
	}*/
	
	public String report(){
		return SUCCESS;
	}
	//下面进行报表
	/**
	 * 查询上个月和这个月 账号注册
	 * @throws IOException 
	 */
	public void reportUser() throws IOException{
		HttpServletResponse resp = ServletActionContext.getResponse();
		resp.setContentType("application/json;charset=UTF-8");
		PrintWriter out = null;
		//首先查询本月和上个月用户总人数
		List<User>	users = userService.findSYuser();
		List<User>	users2 = userService.findBYuser();
		List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
		Map<String, Object> map1 = new HashMap<String, Object>();
		map1.put("NAME", getsy());
		if(users != null && users.size()>0){
			map1.put("TOTAL", users.size());
		}else{
			map1.put("TOTAL", 0);
		}
		
		Map<String, Object> map2 = new HashMap<String, Object>();
		map2.put("NAME", getBy());
		if(users2 != null && users2.size()>0){
			map2.put("TOTAL", users2.size());
		}else{
			map2.put("TOTAL", 0);
		}
		list.add(map1);
		list.add(map2);
		
		 //创建Option
	    GsonOption option = new GsonOption();
	    option.title("注册人数").tooltip(Trigger.axis).legend("数量(人)");
	    //横轴为值轴
	    option.xAxis(new ValueAxis().boundaryGap(0d, 0.01));
	    //创建类目轴
	    CategoryAxis category = new CategoryAxis();
	    //柱状数据
	    Bar bar = new Bar("月份");
	    //饼图数据
	    Pie pie = new Pie("月份");
	    //循环数据
	    for (Map<String, Object> objectMap : list) {
	        //设置类目
	        category.data(objectMap.get("NAME"));
	        //类目对应的柱状图
	        bar.data(objectMap.get("TOTAL"));
	        //饼图数据
	        pie.data(new PieData(objectMap.get("NAME").toString(), objectMap.get("TOTAL")));
	    }
	    //设置类目轴
	    option.yAxis(category);
	    //饼图的圆心和半径
	    pie.center(900,380).radius(100);
	    //设置数据
	    option.series(bar, pie);
	    //由于药品名字过长,图表距离左侧距离设置180,关于grid可以看ECharts的官方文档
	    option.grid().x(180);
	    //返回Option
	    out = resp.getWriter();
		 out.write(option.toString());
	}
	
	
	  public String getBy(){
		  Calendar c = Calendar.getInstance();
		   c.add(Calendar.MONTH, -0);
		  SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM");
		  String time = format.format(c.getTime());
		  System.out.println(time);
		  return time;
	}
	  
	  public String getsy(){
		  Calendar c = Calendar.getInstance();
		   c.add(Calendar.MONTH, -1);
		  SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM");
		  String time = format.format(c.getTime());
		  System.out.println(time);
		  return time;
	}
	  
	  
	  public void reportSay() throws IOException{/*
		  HttpServletResponse resp = ServletActionContext.getResponse();
			resp.setContentType("application/json;charset=UTF-8");
			PrintWriter out = null;
			//首先查询本月和上个月用户总人数
			List<SayMood>	users = sayMoodService.findSYusay();
			List<SayMood>	users2 = sayMoodService.findBYsay();
			List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
			Map<String, Object> map1 = new HashMap<String, Object>();
			map1.put("NAME", getsy());
			if(users != null && users.size()>0){
				map1.put("TOTAL", users.size());
			}else{
				map1.put("TOTAL", 0);
			}
			
			Map<String, Object> map2 = new HashMap<String, Object>();
			map2.put("NAME", getBy());
			if(users2 != null && users2.size()>0){
				map2.put("TOTAL", users2.size());
			}else{
				map2.put("TOTAL", 0);
			}
			list.add(map1);
			list.add(map2);
			
			 //创建Option
		    GsonOption option = new GsonOption();
		    option.title("发表图片数").tooltip(Trigger.axis).legend("数量(人)");
		    //横轴为值轴
		    option.xAxis(new ValueAxis().boundaryGap(0d, 0.01));
		    //创建类目轴
		    CategoryAxis category = new CategoryAxis();
		    //柱状数据
		    Bar bar = new Bar("月份");
		    //饼图数据
		    Pie pie = new Pie("月份");
		    //循环数据
		    for (Map<String, Object> objectMap : list) {
		        //设置类目
		        category.data(objectMap.get("NAME"));
		        //类目对应的柱状图
		        bar.data(objectMap.get("TOTAL"));
		        //饼图数据
		        pie.data(new PieData(objectMap.get("NAME").toString(), objectMap.get("TOTAL")));
		    }
		    //设置类目轴
		    option.yAxis(category);
		    //饼图的圆心和半径
		    pie.center(900,380).radius(100);
		    //设置数据
		    option.series(bar, pie);
		    //由于药品名字过长,图表距离左侧距离设置180,关于grid可以看ECharts的官方文档
		    option.grid().x(180);
		    //返回Option
		    out = resp.getWriter();
			 out.write(option.toString());
	  */}
}

如果也想学习本系统,下面领取。关注并回复:040ssh

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夜未央5788

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值