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. 后端:Spring+Struts+Hibernate

2. 前端:JSP+CSS+JavaScript

使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中src/com/DB/connDB.java配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入http://localhost:8080/ 登录
用户账号/密码:user/123456

管理员账号/密码:admin/admin

运行截图

用户角色

 

 

 

 

管理员角色

 

 

 

 

 

 

 

相关代码 

BaseActionSupport

/**
 * 功能:各action类共用的基础类,各类的共用方法在这里调用。
 * 使用:各子类调用.
 * 修订说明: 
 *
 *   新增代码
 *
 */
package com.action;

import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.util.PageUtil;

public abstract class BaseActionSupport extends ActionSupport{
	public String msg;
	private int pageSize = 10;
	private long totalCount;
	
	/**
	 * 将所有URL参数合并成一个URL字符串(page参数除外), 提供分页时显示.
	 * @return 字符串, 如: para1=11&para2=bb
	 */
	public String mergeParamsAsURI() {
		Map<String, String[]> params = getRequest().getParameterMap();
		
		StringBuffer out = new StringBuffer();
		
		Set<String> keys = params.keySet();
		
		for (String key : keys) {
			if(!"page".equals(key)){
				// TODO 发现Map值有乱码
				String[] values = params.get(key);	
				if(values.length > 1) {
					values = getRequest().getParameterValues(key);
				} else {
					values = new String[] {getParameter(key)};
				}
				System.out.println("key=========" + key);		
				try {
					for(String value : values) {
						System.out.println("value=" + value);
						out.append(java.net.URLEncoder.encode(key, "UTF-8") + "=");
						out.append(java.net.URLEncoder.encode(value, "UTF-8") + "&");
					}

				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
				}
			}
		}
		// 删除末尾多余的 & 字符
		if(out.toString().endsWith("&")) {
			out.deleteCharAt(out.length() - 1);
		}
		
		return out.toString();
	}
	
	/**
	 * 从请求中取得offset的参数值
	 * @param request
	 * @return
	 */
	public Integer getOffset(){
		String os =getRequest().getParameter("pager.offset");
		int offset =0;
		try{
			offset =Integer.parseInt(os);
		}catch (Exception e) {
			offset =0;
		}
		return offset;
	}

	/**
	 * 读取表单参数
	 * @param name
	 * @return
	 */
	public String getParameter(String name) {
		String value = ServletActionContext.getRequest().getParameter(name);
		try {
			if(value!=null) {
//				value = new String(value.getBytes("ISO-8859-1"),"UTF-8");
			}
		}catch(Exception e) {
			e.printStackTrace();
		}
		return value;
	}
	/**
	 * 获取转码后的值
	 * @param value
	 * @return
	 */
	public String getValue(String value) {
		try {
			if(value!=null) {
//				value = new String(value.getBytes("ISO-8859-1"),"UTF-8");
				System.out.println(value);
		}}catch(Exception e) {
			e.printStackTrace();
		}
		return value;
	}
	
	/**
	 * 将表单参数作为整数返回.
	 * @param name 表单参数名
	 * @return
	 */
	public int getParameterInt(String name) {
		String s = getParameter(name);
		//判断String s是否为空
		if(s == null) {
			return 0;
		} else {
			try {
				return Integer.parseInt(s);
			} catch (NumberFormatException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return 0;
	}
	/**
	 * 获取请求对象.
	 * @return
	 */
	public static HttpServletRequest getRequest() {
		return ServletActionContext.getRequest();
	}
	/**
	 * 获取请求对象.
	 * @return
	 */
	public static HttpServletResponse getResponse() {
		return ServletActionContext.getResponse();
	}
	/**
	 * 设置 request 的属性.
	 * @param name 属性名
	 * @param value 属性值
	 */
	public void setAttribute(String name, Object value) {
		ServletActionContext.getRequest().setAttribute(name, value);
	}
	
	/**
	 * 获取 request 的属性.
	 * @param name 属性名
	 */
	public Object getAttribute(String name) {
		return ServletActionContext.getRequest().getAttribute(name);
	}	
	/**
	 * 向 session 设置属性值
	 * @param name
	 * @param value
	 */
	public static void setSession(Object name, Object value) {
		ActionContext ctx = ActionContext.getContext();
		Map session = ctx.getSession();
		session.put(name, value);
	}
	/**
	 * 向 session 设置属性值
	 * @param name
	 * @param value
	 */
	public  static Object getSession(String name) {
		ActionContext ctx = ActionContext.getContext();
		Map session = ctx.getSession();
		return session.get(name);
	}
	

	public String getMsg() {
		return msg;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public long getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(long totalCount) {
		this.totalCount = totalCount;
	}

	
	
	
}

ForumAction

package com.action;

import java.text.SimpleDateFormat;
import java.util.List;

import com.model.TbDetailDto;
import com.model.TbForumDto;
import com.model.TbMember;
import com.service.ForumService;
import com.util.PageUtil;




public class ForumAction extends BaseActionSupport {
	
	private ForumService forumService;
	private TbForumDto forumdto;
	private TbDetailDto detaildto;
	private String forumd;
	
	//后台
	public String search() throws Exception{
		String hql = "select count(*) from TbForum";
		PageUtil pageUtil = new PageUtil();
		pageUtil.setPaged(this.getOffset());
		this.setPageSize(10);
		pageUtil.setPageSize(10);
		List list = forumService.search(pageUtil);
		this.setTotalCount(this.forumService.countRecord(hql));
		setAttribute("forumList",list);
		return "searchSuccess";
	}
	/**
	 * 显示后台论坛标题详细
	 * @return
	 * @throws Exception
	 */
	public String searchDetail() throws Exception{
		String hql="select count(*) from TbDetail where forumid='"+forumdto.getTbForum().getId()+"'";
		PageUtil pageUtil = new PageUtil();
		pageUtil.setPaged(this.getOffset());
		this.setTotalCount(this.forumService.countRecord(hql));
		List list = forumService.searchDetail(forumdto.getTbForum().getId(), pageUtil);
		setAttribute("detailList",list);
		return "searchDetaiSuccess";
	}
	
	//前台
	public String searchQ() throws Exception{
		String hql = "select count(*) from TbForum";
		PageUtil pageUtil = new PageUtil();
		pageUtil.setPaged(this.getOffset());
		this.setTotalCount(this.forumService.countRecord(hql));
		List list = forumService.search(pageUtil);
		setAttribute("forumList",list);
		
		return "searchQSuccess";
	}
	
	public String insertInit()throws Exception{
		return "insertInitSuccess";
	}
	
	public String insert()throws Exception{
		
		SimpleDateFormat date=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String currentDate=date.format(new java.util.Date());
		forumdto.getTbForum().setIntime(currentDate);
		TbMember user  = (TbMember)getRequest().getSession().getAttribute("username");
		forumdto.getTbForum().setFather(user.getUserName());
		forumService.insert(forumdto);
		return "insertSuccess";
	}
	
	
	public String detailInit()throws Exception{
		return "detailInitSuccess";
	}
	
	public String insertDetail()throws Exception{
		
		SimpleDateFormat date=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String currentDate=date.format(new java.util.Date());
		detaildto.getTbDetail().setForumid(forumd);
		detaildto.getTbDetail().setIntime(currentDate);
		TbMember user  = (TbMember)getRequest().getSession().getAttribute("username");
		detaildto.getTbDetail().setWho(user.getUserName());
		forumService.insertDetail(detaildto);
		return "insertDetailSuccess";
	}
	/**
	 * 前台显示详细
	 * @return
	 * @throws Exception
	 */
	public String detail() throws Exception{
		String hql="select count(*) from TbDetail where forumid='"+forumdto.getTbForum().getId()+"'";
		PageUtil pageUtil = new PageUtil();
		pageUtil.setPaged(this.getOffset());
		this.setTotalCount(this.forumService.countRecord(hql));
		List list = forumService.detail(forumdto.getTbForum().getId(),pageUtil);
		setAttribute("list", list);//取论坛主表
		List detail = forumService.forumdetail(forumdto.getTbForum().getId(),pageUtil);
		setAttribute("detail", detail);//取论坛明细
		return "detailSuccess";
	}
	
	
	public String delete()throws Exception{
		forumService.delete(forumdto);
		setAttribute("mess", "信息删除成功!");
		return "deleteSuccess";
		
	}
	public String deleteDetail()throws Exception{
		forumService.deleteDetail(detaildto);
		setAttribute("mess", "信息删除成功!");
		return "deleteDetailSuccess";
		
	}
	
	
	public ForumService getForumService() {
		return forumService;
	}
	public void setForumService(ForumService forumService) {
		this.forumService = forumService;
	}
	public TbForumDto getForumdto() {
		return forumdto;
	}
	public void setForumdto(TbForumDto forumdto) {
		this.forumdto = forumdto;
	}

	public TbDetailDto getDetaildto() {
		return detaildto;
	}

	public void setDetaildto(TbDetailDto detaildto) {
		this.detaildto = detaildto;
	}

	public String getForumd() {
		return forumd;
	}

	public void setForumd(String forumd) {
		this.forumd = forumd;
	}

	

	
}

LineAction

package com.action;

import java.util.List;

import com.model.TbLine;
import com.model.TbLineDto;
import com.service.LineService;
import com.util.PageUtil;

/**
 * 线路管理类
 * @author Administrator
 *
 */
public class LineAction extends BaseActionSupport {
	private LineService lineService;
	private TbLineDto linedto;
	
	/**
	 * 查询按钮
	 * @return 字符
	 */
	public String searchInit() throws Exception{
		if(linedto != null) {
			linedto=new TbLineDto();
		}
		
		List list = lineService.searchInit();
		setAttribute("lineList",list);
		return "searchInitSuccess";
	}

	public String searchQInit() throws Exception{
		if(linedto != null) {
			linedto=new TbLineDto();
		}
		
		List list = lineService.searchInit();
		setAttribute("lineList",list);
		return "searchQInitSuccess";
	}

	/**
	 * 前台查询方法
	 * @return
	 * 
	 */
	public String searchQ(){
		try {
			String hql = "select count(*)from TbLine where 1=1";
			if(linedto==null) {
				linedto = new TbLineDto();
			}else if(linedto.getTbLine()!=null){
				//公共部分
				if ( linedto.getTbLine().getNameboard()!=null&&!"".equals(linedto.getTbLine().getNameboard())){
					linedto.getTbLine().setNameboard(this.getValue(linedto.getTbLine().getNameboard()).trim());
					hql =hql+" and nameboard like '%"+linedto.getTbLine().getNameboard()+"%'";
				}
				if (linedto.getTbLine().getSite()!=null&&!"".equals(linedto.getTbLine().getSite())){
					String site = this.getValue(linedto.getTbLine().getSite());
					linedto.getTbLine().setSite(site.trim());
					hql =hql+" and site like '%"+linedto.getTbLine().getSite().trim()+"%'";
				}
				//输入起点和终点时找到类似满足不要换乘的线路
				if (!"".equals(linedto.getTbLine().getRouteend()) && !"".equals(linedto.getTbLine().getRoutef())){
					linedto.getTbLine().setRouteend(getValue(linedto.getTbLine().getRouteend()).trim());
					linedto.getTbLine().setRoutef(getValue(linedto.getTbLine().getRoutef()).trim());
					hql =hql+" and site like '%"+linedto.getTbLine().getRoutef().trim()+"%"+linedto.getTbLine().getRouteend().trim()+"%'";
				}
			}
			//分页查询条件设置
			this.setTotalCount(this.lineService.countRecord(hql));
			PageUtil pageUtil = new PageUtil();
			pageUtil.setPaged(this.getOffset());
			
			List list =lineService.search(linedto,pageUtil);
			
			int count = 0;
			if(linedto.getTbLine()!=null && !linedto.getTbLine().getRoutef().equals("") && !linedto.getTbLine().getRouteend().equals("")
					&& list!=null && list.size()==0 ){
				//如果直达线路找不到,则换乘搜索
				List<TbLineDto> dtoList  = this.lineService.changeSearch(linedto);
				count = dtoList.size();
				if(dtoList != null && dtoList.size()!=0) {
					this.setTotalCount(dtoList.size());
					//换乘分页
					this.setPageSize(10);
					if(this.getOffset()+this.getPageSize()>dtoList.size()){
						dtoList = dtoList.subList(this.getOffset(),dtoList.size());
					}else {
						dtoList = dtoList.subList(this.getOffset(),this.getOffset()+this.getPageSize());
					}
					
					super.getRequest().setAttribute("list", dtoList);
				}
				super.getRequest().setAttribute("count", count);
				return "changeSuccess";
			}
			if(list==null || list.size()==0) {
				super.getRequest().setAttribute("count", count);
				return "changeSuccess";
			}
			setAttribute("lineList", list);
		}catch(Exception e) {
			e.printStackTrace();
		}
		return "searchQSuccess";
		
	}
	/**
	 * 查询方法
	 * @return
	 * 
	 */
	public String search(){
		String hql = "select count(*)from TbLine where 1=1";
		if(linedto==null) {
			this.linedto = new TbLineDto();
		}
		if(this.linedto.getTbLine()!=null) {
			//公共部分
			if ( linedto.getTbLine().getNameboard()!=null&&!"".equals(linedto.getTbLine().getNameboard())){
				linedto.getTbLine().setNameboard(this.getValue(linedto.getTbLine().getNameboard()).trim());
				hql =hql+" and nameboard like '%"+linedto.getTbLine().getNameboard()+"%'";
			}
			if (linedto.getTbLine().getSite()!=null&&!"".equals(linedto.getTbLine().getSite())){
				String site = this.getValue(linedto.getTbLine().getSite());
				linedto.getTbLine().setSite(site.trim());
				hql =hql+" and site like '%"+linedto.getTbLine().getSite().trim()+"%'";
			}
		
			//后台查询
			if (linedto.getTbLine().getRouteend()!=""&&!"".equals(linedto.getTbLine().getRouteend())){
				linedto.getTbLine().setRouteend(getValue(linedto.getTbLine().getRouteend()).trim());
				hql =hql+" and routeend like '%"+linedto.getTbLine().getRouteend().trim()+"%'";
			}
			if (linedto.getTbLine().getRoutef()!=""&&!"".equals(linedto.getTbLine().getRoutef())){
				linedto.getTbLine().setRoutef(getValue(linedto.getTbLine().getRoutef()).trim());
				hql =hql+" and routef like '%"+linedto.getTbLine().getRoutef().trim()+"%'";
			}
		}
		this.setTotalCount(this.lineService.countRecord(hql));
		PageUtil pageUtil = new PageUtil();
		pageUtil.setPageSize(10);
		this.setPageSize(10);
		pageUtil.setPaged(this.getOffset());
		List list =lineService.search(linedto,pageUtil);
		setAttribute("lineList", list);
		return "searchSuccess";
		
	}
	/**
	 * 删除操作
	 * @return
	 * @throws Exception
	 */
	public String delete()throws Exception{
		lineService.delete(linedto);
		setAttribute("mess", "信息删除成功!");
		return "deleteSuccess";
		
	}
	
	
	/**
	 * 编辑按钮
	 * @return
	 * @throws Exception
	 */
	public String updateInit()throws Exception{
		setAttribute("title", "更新");
		List<TbLine> list = lineService.updateInit(linedto.getTbLine().getId());
	 // 将结果取出,赋给line
		TbLine line = (TbLine) list.get(0);
		linedto.setTbLine(line);
		return "updateInitSuccess";
		
	}
	
	/**
	 * 编辑保存按钮
	 */
	public String update()throws Exception{
		lineService.update(linedto);
		setAttribute("mess", "信息保存成功!");
		return "updateSuccess";
		
	}
	
	/**
	 * 添加按钮初始化
	 * @return
	 * @throws Exception
	 */
	public String insertInit()throws Exception{
		setAttribute("title", "添加");
		return "insertInitSuccess";
		
	}
	
	/**
	 * 添加按钮保存操作
	 * @return
	 * @throws Exception
	 */
	public String insert()throws Exception{
		
    	lineService.insert(linedto);
    	setAttribute("mess", "信息保存成功!");
    	return "insertSuccess";
	}

	//显示详细
	public String lineDetail() throws Exception{
		String flag = this.getRequest().getParameter("flag");
		//搜索
		if(flag!=null && !flag.equals("")) {
			List list = lineService.lineDetail(linedto.getTbLine().getId(),Integer.parseInt(flag));
			TbLine line=(TbLine) list.get(0);
			line.setVotes(line.getSite().split("-"));
			String str[]=line.getVotes();
			list.add(line);
			setAttribute("list", list);
			setAttribute("str", str);
			return "detail";
		}else {
			String name = this.getParameter("name");
//			name = new String(name.getBytes("ISO-8859-1"),"UTF-8");
			List list = lineService.lineDetail(name.trim(),0);
			if(list!=null && list.size()>0) {
				TbLine line=(TbLine) list.get(0);
				line.setVotes(line.getSite().split("-"));
				String str[]=line.getVotes();
				if(list.size()>=1) {
					TbLine line1=(TbLine) list.get(0);
					line1.setVotes(line1.getSite().split("-"));
					String str1[]=line1.getVotes();
					int size1 = str.length;
					int size2 = str1.length;
					setAttribute("list", list);
					setAttribute("str", str);
					setAttribute("str1", str1);
					setAttribute("size2", size2);
					setAttribute("size1", size1);
				}
			}
			return "lineDetailSuccess";
		}
	}
	
	//公交预览
	public String lineScan(){
		PageUtil pageUtil = new PageUtil();
		pageUtil.setPaged(this.getOffset());
		List list = this.lineService.lineScan(pageUtil);
		this.setTotalCount(this.lineService.countLinebyName());
		setAttribute("list", list);
		return "lineScan";
	}
	
	
	public LineService getLineService() {
		return lineService;
	}

	public void setLineService(LineService lineService) {
		this.lineService = lineService;
	}

	public TbLineDto getLinedto() {
		return linedto;
	}

	public void setLinedto(TbLineDto linedto) {
		this.linedto = linedto;
	}



}

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

夜未央5788

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

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

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

打赏作者

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

抵扣说明:

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

余额充值