基于javaweb的JSP+Servlet火车票网上订购服务系统(java+jsp+mysql+tomcat)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

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

适用

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

功能说明

392223083009

392223083008

402223083008

412223083008

422223083008

432223083008

442223083008

462223083008

472223083008

482223083008

基于javaweb的JSP+Servlet火车票网上订购服务系统(java+jsp+mysql+tomcat)

管理员
admin 123456

用户:
123456789 123456

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
 */
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
//设置传输数据编码方式
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
//获取前台传送的变量,账号,密码和用户类型
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();
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
			}
}else if("lp".equals(flgs)){
int bls=db.deleteOrUpdate("update dpiao set lyflag='已领票' where id="+id);
if(bls>0){
json.put("dt", 1);
json.put("msg", "领票成功。");
}else{
json.put("dt", 0);
json.put("msg", "lperror:01");
}
}else if("tp".equals(flgs)){
int bls=db.deleteOrUpdate("delete from dpiao where id="+id);
if(bls>0){
json.put("dt", 1);
json.put("msg", "退票成功。");
}else{
json.put("dt", 0);
json.put("msg", "tperror:01");
}
}else if("del".equals(flgs)){
int bls=db.deleteOrUpdate("delete from dpiao where id="+id);
if(bls>0){
json.put("dt", 1);
json.put("msg", "删除成功。");
}else{
json.put("dt", 0);
json.put("msg", "tperror:01");
}
}else{
json.put("dt", 0);
}
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
}

}


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
	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 {
//设置传输数据编码方式
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();
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
		DbConn db2=new DbConn();
if(db.checkTrue("select id from xianlu where tid="+tid+" and zdid="+zdid)){
json.put("msg", "该线路已有该站点");
}else if(db2.checkTrue("select id from xianlu where tid="+tid+" and xh="+xh)){
json.put("msg", "站点序号已存在");
}else{
boolean bl=db.insort("insert into xianlu(xh,tid,zdid) values("+xh+","+tid+","+zdid+")");
if(!bl){
json.put("msg", "添加成功。");
}else{
json.put("msg", "添加失败");
}
}
}
//车票信息添加
//data:{tname:'piao',"szdid":szdid,"stime":stime,"ezdid":ezdid,"pval":pval,"ptype":ptype,
//"cxzh":cxzh,"yxsj":yxsj,"tid":tid,idi:ids},
if("piao".equals(tname)){
String tid=request.getParameter("tid");
String szdid=request.getParameter("szdid");
String ezdid=request.getParameter("ezdid");
String stime=request.getParameter("stime");
String pval=request.getParameter("pval");
String ptype=request.getParameter("ptype");
String cxzh=request.getParameter("cxzh");
String yxsj=request.getParameter("yxsj");
boolean bl=db.insort("insert into piao(szdid,ezdid,tid,stime,pval,ptype,cxzh,yxsj) values("+szdid+","+ezdid+","+tid+",'"+stime+"',"+pval+",'"+ptype+"','"+cxzh+"','"+yxsj+"')");
if(!bl){
json.put("msg", "添加成功。");
}else{
json.put("msg", "添加失败");
}
}
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
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



public class InitLoginSvlt extends HttpServlet {

/**
* Constructor of the object.
*/
public InitLoginSvlt() {
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.
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
		response.setCharacterEncoding("utf-8");
response.setContentType("text/html");
String tid=request.getParameter("tid");
JSONObject json=new JSONObject();
if(!"".equals(tid)&&tid!=null){
DbConn db=new DbConn();
ResultSet rs=db.query("select zhandian.* from xianlu,zhandian where xianlu.zdid=zhandian.id and xianlu.tid="+tid);
List<Zhandian> zdlist=FindService.getZhandian(rs);
json.put("msg", 1);
json.put("zdlist", zdlist);
}else{
json.put("msg", 0);
}
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
}

}





public class CkSvlt extends HttpServlet {

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


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