基于javaweb的JSP+Servlet火车票网上订票系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

管理员
admin 123456

用户
1000001 123456
1000002 123456
1000003 123456

前台功能:用户查询车票信息、登录注册、购票、查看已购车票、修改密码等功能。

后台功能:管理员管理、用户管理、火车信息管理、站点信息管理、线路信息管理、车票信息管理、购票信息管理等。

341523532309

050123132502

后台:

490123122502

500123122502

510123122502

520123122502

530123122502

540123122502

550123122502

560123122502

580123122502

590123122502

前台

000123132502

010123132502

020123132502

030123132502

040123132502

技术框架

JSP Servlet MySQL JDBC Tomcat CSS JavaScript

基于javaweb的JSP+Servlet火车票网上订票系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
String uname=request.getParameter("uname");
String upassword=request.getParameter("upassword");
String utype=request.getParameter("utype");
//创建数据库操作对象
DbConn db=new DbConn();
//sql语句变量定义
String sql="";
int id=-1;
String usname="";
if("gly".equals(utype)){
sql="select id from userinfo where uname='"+uname+"' and upassword='"+upassword+"'";
}else if("cus".equals(utype)){
sql="select id,cname from cusinfo where cidcard='"+uname+"' and cpassword='"+upassword+"'";
}
JSONObject json=new JSONObject();
if("".equals(sql)){
json.put("msg", "系统错误01.");
}else{
ResultSet rs=db.query(sql);
if(rs==null){
json.put("msg", "系统错误02");
}else{
try {
while(rs.next()){
id=rs.getInt("id");
if("cus".equals(utype)){
usname=rs.getString("cname");
}else if("gly".equals(utype)){
usname=uname;
}
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(id!=-1){
HttpSession session=request.getSession();
json.put("msg", 1);
session.setAttribute("username", usname);
session.setAttribute("userid", id);
session.setAttribute("utype", utype);
}else{
json.put("msg", "账号或密码错误。");
}
}
PrintWriter out=response.getWriter();
out.print(json.toString());
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
}

/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}

/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}

/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//设置传输数据编码方式
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("text/html");
HttpSession session=request.getSession();
//获取当前登录用户信息
Object utype=session.getAttribute("utype");
Object userid=session.getAttribute("userid");
//创建json对象
JSONObject json=new JSONObject();
if(utype==null||userid==null){
json.put("msg", "请重新登陆。");
return;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47


public class LoginSvlt extends HttpServlet {

/**
* Constructor of the object.
*/
public LoginSvlt() {
super();
}

/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}

/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}

/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
		sql="select zhandian.*,xh from zhandian,xianlu where zhandian.id=xianlu.zdid and xianlu.tid="+ids+"  order by xh";
hp.setValue("sql", sql);
}else{
sql=hp.readValue("sql");
}
ResultSet rs=db.query(sql);
List<Zhandian> zlist=FindService.getZhandians(rs);
request.setAttribute("alist", zlist);
DbConn db2=new DbConn();
ResultSet rs2=db2.query("select * from zhandian where id not in(select zdid from xianlu where tid="+ids+")");
List<Zhandian> zdlist=FindService.getZhandian(rs2);
request.setAttribute("zdlist", zdlist);
DbConn db3=new DbConn();
Object tn=db3.getOnlyOne("select tname from traininfo where id="+ids);
Traininfo t=new Traininfo();
t.setId(Integer.parseInt(ids));
t.setTname(tn+"");
request.setAttribute("t", t);
request.getRequestDispatcher("/admin/mgxianlu.jsp").forward(request, response);
return;
}
//车票信息管理初始化
if("piao".equals(tname)){
String ids=request.getParameter("tid");
if("1".equals(flgs)){
sql="select tmp.*,zdname as eaddr,tname,traintype from (select piao.*,zdname as saddr from piao,zhandian where piao.szdid=zhandian.id and yxsj='1975-01-01' and zdname like '%0%') tmp,zhandian,traininfo where tmp.tid=traininfo.id and tmp.ezdid=zhandian.id and zdname like '%0%' and 1=0";
hp.setValue("sql", sql);
}else{
sql=hp.readValue("sql");
}
ResultSet rs2=db.query(sql);
List<Piao> plist=FindService.getPiao(rs2);
request.setAttribute("alist", plist);
DbConn db2=new DbConn();
ResultSet rs=db2.query("select * from traininfo");
List<Traininfo> tlist=FindService.getTraininfo(rs);
request.setAttribute("tlist", tlist);
request.getRequestDispatcher("/admin/mgpiao.jsp").forward(request, response);
return;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
					json.put("msg", "error:02");
}
}
}else{
json.put("msg", "error:01");
}
PrintWriter out = response.getWriter();
out.print(json.toString());
out.flush();
out.close();
}

/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}

}
package dp.svlt;




public class DpListSvlt extends HttpServlet {

/**
* Constructor of the object.
*/
public DpListSvlt() {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
		}
}else{
json.put("msg", "操作错误01");
}
}
//站点信息修改
if("zhandian".equals(tname)){
String zdname=request.getParameter("zdname");
String ids=request.getParameter("idi");
ResultSet rs=db.query("select id from zhandian where zdname='"+zdname+"'");
if(rs!=null){
boolean bl=false;
int id=-1;
try {
while(rs.next()){
id=rs.getInt("id");
if(!String.valueOf(id).equals(ids)){
bl=true;
}
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(bl){
json.put("msg", "站点名称已存在");
}else{
int bls=db.deleteOrUpdate("update zhandian set zdname='"+zdname+"' where id="+ids);
if(bls>0){
json.put("msg", "修改成功。");
}else{
json.put("msg", "修改失败");
}
}
}else{
json.put("msg", "操作错误01");
}
}
//车票信息修改
if("piao".equals(tname)){
String tid=request.getParameter("tid");
String szdid=request.getParameter("szdid");


项目链接:
https://javayms.github.io?id=201821252205102ar
https://javayms.pages.dev?id=201821252205102ar